Grouping String Variables With Their Names?
Dec 13, 2010
I am trying to reduce the amount of code I have and make it more maintainable and flexible. (I.E Do it the right way). I have a bunch of (48) Form controls (text boxes) and when I click next on that form I save all their text values to some 48 global string variables. The names of these variables are the same as the Text Boxes but with "_saved" appended to them.
For any given operation instead of having a separate line for each control it's nice to just use a loop. I can easily write some code to operate on each Control (set visibility, enabled etc) by using Me.Controls and a For Each Loop. I can even make collections of fractional groups of the 48 controls. For example, If cntrl.name.startswith("sometext") collection.add or perform some other operation only on that subgroup etc.
I'd like to do something similar with my Saved Public String Variables. For example I would like to do the following loop somehow but don't know how to group Variables together and keep their name in a way where I can define that array or collection on 1 line or just a couple lines.
' But this next line only groups the values
Group_of_string_Variables = {Var1, Var2, Var3, Var4}
For Each Name_of_String_Variable In Group_of_string_variables
[Code].....
But I can not access the name of a variable or find a way to easily group in key/value 48 different ones without needing much more than 50 lines of code to make either a 2-dim array, a collection, or a hash.
I'm sure someone will tell me I should be doing it a completely different way. That would be ok as long as I don't have to change too much of my other code. I thought of making an object of some kind instead of a variable so I could access 2 object properties- name and value then I could group those objects in a collection as I have done before. But that seems like it would be many more lines of code and I'm not sure it would work.
View 6 Replies
ADVERTISEMENT
Sep 8, 2009
I have a class called Trigger. within this class, I can perform a variety of functions, the main of which is to monitor a specific condition. In this class I have a bunch of class variables that are used to setup the condition as well as for information purposes after the condition has executed. All the conditions are stored in a database and when I start the program, I create a New Trigger class for each condition and store the variables (name, desc, action to perform once the condition is met, etc.) I was thinking about changing the class to create a Structure called Configuration where I would store all the variables. But then I would have to save the Configuration within the class so it could be used later on if needed correct?
[Code]...
but in looking at this i realized that I am creating a new structure and then creating a new trigger class where I am saving the Configuration structure which essentially seems the same as just using class variables as I was before. I also looked at creating a Configuration Class and a Trigger Class. then from the main class I would create all the Configurations and have a shared Trigger class that monitored all of them instead of having a single Trigger class for each Configuration. Using this method i could create a hash table that kept track of each configuration that was being monitored and stop it if required.
Does either method sound more appropriate over the other. I am just trying to understand when/why to do things a certain way.
View 4 Replies
Apr 29, 2009
I am looping through a collection of items. Within that loop I need to set variables but they need to be a variable. I tried using lists but for some reason they don't get set properly. Heres what I have so far...
[Code]...
View 1 Replies
Oct 11, 2011
I would like loop through control names at run time. Is it possible to do something like the following:
[Code]...
View 3 Replies
Dec 25, 2009
I have a series of labels to modify through a loop. here's an example of the code i need to modify
lbl1.forecolor = color.black
lbl2.forecolor = ...
I need to iterate the lbl number each time through the loop as the color value will change from label to label.Clueless on how to do so with a loop vs the "long" way of doing code for each separate label. I have 169 to modify each time I change input so I'd rather not unless I have to
View 18 Replies
May 20, 2010
how do I DIM a variable's name using previously declared string varialbes? I have been using PERL for processing data stored in text files but I now have a business need to use VB2008. I would like to do something like this:
dim name1 as string = "ABCD"
dim name2 as string = "123"
'here is the part that I don't know how to do - create a 3rd variable name concatenated from name1 and name2:
dim string.concat({name1,name2}), or maybe use a counter in a line like 'dim namex as string' with x being a counter value.
Essentially I want to dim variables using text strings extracted from a file. In PERL I have declared literals and arrays, such as 'my @$name1', which creates an array named with the contents of $name1. In VB2008 I am not sure how to make this work with the DIM statement.
View 5 Replies
Sep 10, 2009
We have this current VBA program to help us with AutoCAD via the use of a template excel sheet.The setup we have created works well; however occasionally we have two drawings per folder, which often results in, two templates excel sheets of the same name, one overwriting the other. how I can set the active drawing name in a variable that our program uses to check for, then if not present that it creates a copy of out template and then saves it as the active drawings file name which was set as the variable
This would allow our program to locate the associated excel sheet by name then save it by the unique drawing name and prevent existing excel files being overwritten if in the same folder.
;===CODE STARTS HERE===
Option Explicit
Private Objexcel As Excel.Application
Private ObjWorkbook As Workbook
[code]....
View 1 Replies
Oct 6, 2008
This is my first post here at Xtreme VB Talk. I just started programming 2 semesters ago. I am currently working on a program but I am having a little trouble with the length. I am trying to take the integer entered in a text box and using it inside the name of another object.
[Code]...
View 5 Replies
Jun 18, 2009
project i'm working on for school. Need to make a grade calculator thing but I'm trying to make my code more efficient.
This is what I have at the moment:
txtID.Text = ListBox1.SelectedIndex
txtFname.Text = namesarr(ListBox1.SelectedIndex, 0)
[code].....
View 8 Replies
Dec 11, 2011
Last year (2010) I came across a FANTASTIC command that allowed me to take a string of variables with a common delimiter and break it all back out into separate variables (possibly an array) with one statement.
[Code]...
As long as the delimiter was a unique specifiable character, this one-statement command could break it out into elements. my memory and point me in the right direction.
View 2 Replies
Oct 28, 2011
I'm trying to get the list of field names for a given table, to turn them into a string which I can to post back as a variable to another function.I've Googled loads of stuff regarding GetSchemaTable but all I seem to be able to output are field parameters, but not the actual value of these parameters (ie ColumnName, which is the one I actually want!)
Found this page; What is the SQL command to return the field names of a table?But all the queries on there give me an error "You do not have access to Table 'Columns'"I feel sure this is pretty simple, can someone give me a little function that will simply give me fieldNames = "fieldName1, fieldName2, etc"I am using a MySQL server and ODBC connections ASP.NET using VB.
View 1 Replies
Mar 5, 2012
I m trying to write a program that is mostly dynamic. This program enables the user to read in several inputs (temperature, pressure .) and perform calculations on those inputs. After that the program sends an integer to an analogue output port. The program automatically determines the number and type of the inputs. It also creates something called a variable handle for each input.This is then saved to an array input_handler(0,x). That array is sized this way input_handler(0 to 1 , 0 to 9)
0= handle (integer)
1= value (integer)
The program dynamically creates a button for every input. There also is a button for every mathematical operator. This way the user can create a function by pressing buttons.This function will be saved to a string. That string will look something like this input_handler(1,0)+ input_handler(1,4)/ input_handler(1,3)Well now Im stuck with a string and VB will obviously just print out that string instead of calculating anything. Is there any conversion I can perform so that string becomes the actual array values?
View 8 Replies
Aug 19, 2010
Can I change the following code and safely obfuscate it ? or that I must exclude it from obfuscating (e.g. stackoverflow 2555355 obfuscating-asp-net-dll / 2555497#2555497 )
Dim fontNames As New ArrayList
. . .
Me.myCtrlCmbFontName.DataSource = fontNames
[CODE]...
View 2 Replies
Mar 15, 2012
I don't know if I explained this in my title, this is what i want to do. (In VB on a active server page) I have 5 buttons called but1.....but2. Right now I have the following code to make them invisible
but1.Visible=false;
but2.Visible=false;
but3.Visible=false;
but4.Visible=false;
but5.Visible=false,
Is there a way to access the objects by using a string, example
for(i=i;i<6;i++
items("but"+str(i)).visible=false
View 1 Replies
Jun 10, 2011
I'm using a Microsoft Word form template to create objects in a form programatically, so depending on the information read by the program from the template.
So, I've got some fields where I store formula data for the form, in which I specify that the value for that field is obtained by multiplying other fields in the template. So I store in the string something like this:
"Text1.Text * Text2.Text"
So I need to convert these string values into variable calls to actually operate these values.
View 2 Replies
Apr 8, 2009
How can I get all the names of the shortcuts icons in the desktop into a String?
Like: Computer, Microsoft Office Word 2003, Internet Explorer....etz.
I tried to use "My.Computer.FileSystem..." , but didn't find a way.
View 3 Replies
Aug 23, 2010
I am writing an app to streamline my downloading and reading or manga, i usually download and manually extract each chapter into a specific location, based on what manga and chapter number it is. i then use windows picture viewer to read it.however, i can't work out a procedure that would take the manga name and chapter number out of the file name.i want to be able to pass the procedure a string containing the format that the file name is. e.g. "<title>_<chapter>_[IEM]" then i want the procedure to return the manga title and chapter umber into variables.for example, i pass the function "<title>_<chapter>_[IEM]" as the format string and [code]...
View 6 Replies
Feb 2, 2011
If I use code such as NewName = StrConv(OrigName, vbProperCase) to convert names to proper case, i.e. with initial capitals, I get unwanted results with Irish names like the following:
O'neill instead of O'Neill
O'grady instead of O'Grady
[code].....
View 7 Replies
Mar 7, 2009
Ive looked it up, nothing really worked on 2008, I have a string that always the same length, and want to split it up into variables. The string looks like:
0-555-555
I have 3 designated variables for each number and I don't want to put them into an array.
View 1 Replies
May 28, 2012
What I'm trying to do here is Capture 2 Variables from a Textbox
Here is an example of whats going to be in here.
User:Pass
I want to declare everything before the : as user and everything after the : as pass.
I've Googled, and found a few things, but I couldn't seem to get it working fully.
View 3 Replies
Dec 26, 2010
In the following code i want to replace 'Product7' (in the line : sql = "delete product where Product_name ='Product7'") with a string variable:
dim x as string
x = "example"
how to do it ?
Imports System.Data.SqlClient
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim connetionString As String
[Code] .....
View 17 Replies
Feb 15, 2011
I have a collection of strings that I got from splitting another string. I now need to get each value of the collection into seperate strings.[code]...
View 8 Replies
Feb 5, 2009
Is there a way toi insert , say, integer variable in the middle of a message box string. I can tack it on at the end but can't get it in the middle.Say,
Dim number as integer
number = 6
Messagebox.show("You have visited &number& times")
[code].....
View 7 Replies
Jul 11, 2011
I need to split one variable into 3 variables. For example I have a variable called Data and it contains AAA00000001. I need to have them be split between the "AAA", "0000000", and "1". I looked at the Split() function but didn't get a clear example for this situation. The reason I need to do this is because I want to store these 3 variables into fields for a MySQL database.
View 3 Replies
Jul 20, 2011
I recently discovered that VB.NET 2010 lets you initialize strings by embedding them in tags instead of between double quotes. This is especially handy for spitting out raw xml and multi line strings.Is there a way to embed variables into the string? For example:[code]
View 5 Replies
Nov 11, 2010
It's just a small calculator project so it's no big deal, but after I had built the project, I wanted to change the project name and all the file names that had that string in it (and all internal references to that string). I had played with this before and knew that it was asking for trouble but I thought, "What the hell, I'll try it again." feeling a bit brash.
Well, everything works fine in debug mode, but there is this DOS window that pops up just before the main form does, and it doesn't go away for the entire debugging session. I think I see that window pop up on all other projects too (if the main form doesn't cover it up completely), but normally, it's only there for a split second.
View 2 Replies
Jun 11, 2010
I am trying to input a very long list of dog breed names into a DB via phpmyadmin, this will take me for ever manualy and I was thinking if I could work out how to write something quick and nasty to create the sql string for each dog breed it would save me so much time. The sql query for each added forum is in the following format:
[Code]...
View 4 Replies
May 23, 2009
how do i compare 2 string variables to determine if they are the same?ie:
if(string1 = string2 AND string3= string 4) then
perform operation
else
perform another operation
end if
View 2 Replies
Jun 8, 2009
If I typed in "Dim X as Integer" in a text box, I figured that I could just use If TextBox1.contains to make vb.net dim it. However, how would, if I typed "X = 3y * 9" in the text box, actually calculate that and print it in another text box?
View 5 Replies
Jan 11, 2011
I'm trying to insert variables into my connection string hoping that they will be saved for executing multiple queries.
What I'm trying is something like this:
Private sConnectionString As String = "Provider=TDOLEDB;Data Source=TDDEV;Persist Security Info=True;User ID="&user&";Password="&pass&";Default Database=bcpm_ddbo;Session Mode=ANSI;"
[Code].....
View 4 Replies