Use Text From INI File As Variable Names
I need to dynamically create variables from the variable names and their values stored in an INI file, essentially. There are about 250 of them to create and I don't want all that to be static in my prog...not good programming.
Here is a sample from the settings file:
Where basically I need to do this
Code:Dim USER_NAME As String
USER_NAME = "UserName"
p.s. I know how to use the GetPrivateProfileSection, GetPrivateProfileString, WritePrivateProfileString stuff. It's not that. If you need more info, please post.
View Complete Forum Thread with Replies
See Related Forum Messages: Follow the Links Below to View Complete Thread
Opening A Series Of Text Files, With Variable Names...
I am trying to add a function to a program - here's what I need it to do:
Open a series of txt files, bringing the content into a listbox. I am quite competent at opening and importing one file, but I need to be able to open how ever many txt files appear in a certain folder.
To make it more complicated, each txt file is date stamped, so every one will be different.
Looking at the proposition I see the following:
1. Check the particular folder to see what files are in there
2. Open the first one and read in the details into a listbox
3. Open the second one...
I've not come across this one before, so can anyone offer any advice on how to approach it?
Need To Grab Names From Php Into Text File Through VB
Just now started my prep on VB.Got this problem plz help my kind VB soulz
i have a list of names on my site and i want to know how i can handle them.let's take for example in http://www.vbforums.com/memberlist.p...name&order=asc have a username list there right?
i need all those names on one txt file no matter whether its a php or HTML using visual basic.
Save Text File In Different Names
i'm creating a keylogger in vb6. this is the piece of code i use to save the text file.
Open "c:yourfile.txt" For Output As #1
Print #1, Text1.Text
i used this code in the timer, so that it'll save the text file automatically. it works. but instead of 'yourfile.txt', i want the name of the text file to be the current time of my computer. how do i change the codings for this?.....pls ans asap....thnx in advance.....
Scanning A Dir For Names In A Text File
I have a listview with a list of files populated in it. What I want to do is remove the listitem if the file exists in a specified folder. This will show me what files I don't have.
I have a text file with a list of file names in it. So line one and two would be:
I want to either :
a.) read the contents of the text file (line by line) and check if the zip file name exists in a specified folder.
b.) read the contents of the specified folder and check if the zip file name exists in the text file.
Whichever is more logical (I don't have much logic )
Then remove it from the listview if it exists, giving me a listview with only filenames that aren't in the specified folder.
Thanks, and appologies if I'm not making myself clear.
Is It Possible To Store Command Names In A Text File?
This is what I am attempting to do. I am building a wizard with only one form and all the text, help and control names stored in a ini file. As the user makes selection the form gets updated by reading the next section in the ini of that sequence.
So lets say my ini file looks like this
Can I read those from the file and then have them execute a .show in the code. Basically is there a way to have a variable take the place of a command name, so I can reference txtdesc.text as strFiledata & .text?
Is this possible?
Loading Names Of Files Into A Data Base Or Text File
I need to put to gether a program for mangeing data at work. I need to know how to look in a directory and load the names of the files in it to either text file or preferbly a data base file. I need the code and explicet instructions on how to use the code(I'm still trying to get used to VB)
W2000 File Names In FileListBox Are Are Dos Format Rather The Long Names
I have developed an application in VB5 under Windows 98. I am compiling the task and placing it in a network directory for common execution so an install is unnecessary. When the task is run from a W2000 box the long file names in a filelistbox get truncated to the old dos format maintaining the extension.
i posted this in the VBA section but this can also be applied to General problems... keep in mind that i am using VBA (ie i can't use index values)
OK, here is my problem: i have a form with 100 tetboxes in 10 rows and ten columns. In a previous form the user decides how many rows and columns he/she wants to have visible. The text boxes are named based on their position in the row/column. ie MM23 would be a textbox in the second column and third row. How can i use a counted loop to reference these textboxes and make the appropriate ones not visible? is there a way to use a variable in the name of the textbox? or some way of using callbyname?
ANY and all help is greatly appreciated
I want to use the variable "currentArray". it will be set as either "numbr" or "memA" how can I use this, say in the following way:
currentArray & "sign" ="+"
so that hopefully i would get either
numbrsign = "+"
memAsign = "+"
so that depending on currentArray it either changes one of 2 variables,
I've got a application were there are several text boxes, labelled text1, text2, text3 etc.
No what I want to do is populate these text boxes within a loop so that I don't have to repeat the same code.
Is there way in vb to to contruct the name of a variable (eg. text1) with a loop. I tried doing the following but it obviously made no sense (this is a example):
for i = 1 To 10 Step 1
"text" + i = "this box" + i
If you know what I'm trying to do, could please help me out.
What is the maximum length that I can give a variable in vb?
What happens if I exceed this length?
$ And && In Variable Names
Does this have some special significance? Is it shorthand for string?
Like in something like this:
Function FileExists(sFileName$) As BooleanOn Error Resume Next FileExists = IIf(Dir(Trim(sFileName)) <> "", True, False) End Function
What about "&"?
Is there a way to reference a variable name using a string? Here is an example:
I have a class with many variables labeled as follows:
Is there a way I could loop through the variable names and change the number in the variable name? For example:
For i = 1 to 10
ClassName.L2B & i & Offset = SomeVariableValue
I know this approch won't work but is there some way to accomplish the same thing??
~Of all the things I've lost, I miss my mind the most.~
~Iz vseh veshei chto ya poteryal, ya bol'she vsego skuchayu po rassudku.~
Help With Variable Names
All i want it is to have bob say hi when you click button 0
and have frank say hi when you click button 1
both doen't work
Private Sub hello_Click(Index As Integer)
If Index = 0 Then
name = bob
ElseIf Index = 1 Then
name = frank
Dim hello As New name
if index = 0 then
dim hello as new bob
if index = 1 then
dim hello as new frank
it works if i do a
dim hello1 as new bob
dim hello2 as new frank
but i need to have both of them be hello.hi
Saving Text File With Variable File Name???
Hi, i am using VB 6.0 and i want to save a text file using a varible as part of the file name. Here is what i currently have:
appPath = App.PathIf Right(appPath, 1) <> "" Then appPath = appPath & ""' Get a free file numberFileNum1 = FreeFile' Create mood.txtOpen appPath & "mood.txt" For Append As #FileNum1' Write the contents to mood.txtPrint #FileNum1, mood; ","; minuteFormat(currentTime)' Close the fileClose FileNum1
However this creates a file called mood.txt.
What i need is songTitle mood.txt where songTitle is a variable. songTitle is a String which usually looks something like this;
C:Documents and SettingsuserDesktopsong.mp3
So i want the file as "C:Documents and SettingsuserDesktopsong.mp3 mood.txt" , (actually i would REALLY like it to be "song mood.txt", so if someone coud also show me how to get the actual filename from the whole directory that would be great).
something like that. But using
Open appPath & songTitle & "mood.txt" For Append As #FileNum1
results in a bad filename error.
At first i though maybe it had something to do with the filename having spaces. Could this be it?
Open "appPath & songTitle & "mood.txt"" For Append As #FileNum1
But that just gave a syntax error
Is there a way around this?
Retriving Variable Names
Does anyone know of a method to retrieve Variable names from within a module/procedure/function etc (Im hoping for a similar method that you can use to retreive objects on a form)
Cheers in advance for any pointers in the right direction.
Creating Variable Names On The Fly
Is there any way to declare a variable name with a variable in it?
Fer instance: Dim rs & i as ADODB.Recordset
Does VB let you do this?
I'm trying to create recordsets of n-level depth for recursive data to populate a treeview control. Am I going about this stupidly?
Increasing Variable Names
Is it possible to increase a variable name? I could use a loop instead of repeating with a variable name that only has a number increased at the end.
could be (?)
Let n = n+1
Loop until n>3
Or something like this?
If anyone knows how to do something like this or has a clue, please help me. I know its possible with a file name...
Danny Beaudoin (email@example.com)
Using Variable Component Names
to save me from typing this :
costsheet.lbltotal1.Caption = costsheet.edtmat1.Text + costsheet.edtlab1.Text
300 times for 300 seperate components, just changing the number on the end each time, i though i could do something like this:
Do Until myvar = 300
costsheet.lbltotal(myvar).Caption = costsheet.edtmat1(myvar).Text + costsheet.edtlab(myvar).Text
myvar = myvar + 1
i dont know if i'm on the right lines? i cant seem to work out how to do it
can anyone help?
thanks in advance again
Dynamic Variable Names
is there a way to build variablenames at runtime ?
We got 4 Buttons : But1,But2,But3,But4
and want to apply ReadOnly on all 4 in a loop
For i As Integer = 1 To 4
(But & i.ToString ).ReadOnly = True ' What to do here ?!
Ty for your help.
Creating Variable Names
How can I create variables named from the text in a field?
Example, the user enters "price" in a text box, how could I create a variable named "price" (or whatever the user entered) that contains "9.99"?
Using Variable Table Names In An SP
As a simplification of much more complex issue, here is roughly what I am trying to do in a Stored Procedure.
Select * from @strMyTable
(@strMyTable is a string representing the name of the table passed to the query)
I do not want the complexities of dealing with a table object and declaring table variables with definitions of columns etc when all I simply want is to refer to an arbitrary table by using the string that repesents its name .....why does it seem so complicated?
Is it just me or do other programmers find the syntactical support on the SQL 'Programming Language' aspect truly dismal - if not non-existent.
Variable Form Names
Dim recloadgmform As Recordset
Dim strgmlocation As String
datselectgm.RecordSource = "SELECT GmName, GmLocation FROM tblforms WHERE GmName=" & "'" & strselectedgm & "'" & ""
Set recloadgmform = datselectgm.Recordset
strgmlocation = recloadgmform![GmLocation]
.Data1.DatabaseName = App.Path & "Datadataconvert.mdb"
.Data1.RecordSource = "SELECT * From " & varlocation & " WHERE [QuestionID] = " & RandomNumber & ""
Basically the code above doesn't work because "strgmlocation" is not an object but it doesn't work if i set it to a form instead of string. So how can I make it so when the form name is got from the database it will actually open that form. The "data1" is all the forms that can be loaded.
Variable Command Names
I'm creating a program and I have a little problem.
I have a button for every letter of the alphabet and when a button is clicked, a variable is set to that specific letter and a procedure is run.
Private Sub cmdQ_Click() letter = Q prcLetterEnd Sub
Now I want prcLetter to have a line of code that makes cmd?.Enabled = False
How do I make it so that the variable "letter" replaces the ?.
Getting Variable Names At Runtime
is something like this possible
for each variable in MyModule
Print variables<NAME> & " = " & variables<VALUE>
I thinking something like could be used as a memory dump in an error handler very effectively. I can think of nightmareish way to do it using constants, but I'm looking for something that is clean and tight.
Variable Object Names
Forgive me ahead of time, I'm new to this. I process several files using a VB app. Each file has a txtbox, button and label associated with it and the names of the controls include the name of the file. I want to use a variable to reference all of these things with 1 main process passing 1 value.
Private Sub btnPaycomm_Click()
txtPaycomm.Text = "Processing Paycomm...."
lblPaycomm.ForeColor = VbRed
Call ProcessFile ("Paycomm")
txtPaycomm.Text = "Paycomm Process Completed"
Private Sub btnAccomm_Click()
txtAccomm.Text = "Processing Accomm...."
lblPaycomm.ForeColor = VbRed
Call ProcessFile ("Accomm")
txtAccomm.Text = "Accomm Process Completed"
This repeats over and over for every file. There are like 50 files.
What I vision in my head but doesn't work is below: This way I write the Main Process once and just pass one file name. From all of the 50 buttons.
Private Sub btnPaycomm_Click()
Private Sub btnAccomm_Click()
Public Sub MainProcess(CmdFile)
"txt" & CmdFile & ".Text" = CmdFile & " Processing...."
"lbl" & CmdFile & ".ForeColor = VBRed
Call ProcessFile (CmdFile)
"txt" & CmdFile & ".Text" = CmdFile & " Process Completed"
Any help would be appreciated.
Q'n About Creating Variable Names On The Fly
just wondering how to create variable names that contain a variable
how would you create these names on the fly if the number was a variable?
i was thinking something like
dim i as integer = 0
For i = 1 To 10
dim var+(i) as string = "new variable"
Get Variable Names From A String
Is it possible to derive a variable name from a string? For example, you read the string "English", and you then create a variable (array) named "English". Is there anyway to do this?
Variable Names From Strings?
i'm pretty sure this cant be done, but just makin sure...
is it possible to declare and reference a variable that has a name taken from a string?
this sort of thing...
Dim strString as stringstrString = "varVariable"Dim [b]strString[/b] as variant
Adding Variable Names!
i have this line of code in a vb app:
Picturebox1.Picture = LoadPicture("C:MattCards" & RandomCardName & ".bmp")
i want it to load a picturefrom the file
seen as this file will be randomly choen by an array and stored inthe variabe RandomCardName
now the code above looks for file
can anyone solve it?? heeeeeelp!
How Can I Use A Variable For Table Names In SQL?
How can I use a string array containing many table names, such as the TableName() array below, to query different tables for each value of j%
The syntax below gives me an SQL error.
For j% = 1 To TotalTables
Set history2 = Workspaces(0).OpenDatabase(DBSelected(j%), False, False, ";pwd=;")
qry = "SELECT * FROM ' " & TableName(j%) & " ' WHERE ' " & CallFieldSelected(j%) & " ' = 'P' and '" & AvgDiffFieldSelected(j%) & "' > ' " & Threshold & " ' "
Set ArraySnap(j%) = history2.OpenRecordset(qry, dbOpenDynaset)
Weird Variable Names
say i have option1, option2, option3...all the way to option10
how do i increment the variable name, i tried:
for j = 1 to 10
option[j].text = ""
but that sort of thing doesnt work. ne ideas?
[Edited by Mag-Net on 07-18-2000 at 09:16 AM]
Variable Field Names
I have the floowing
If .RecordCount > 0 Then
Do Until .EOF
If txtNPCode = ![NPCODE] Then
I want be able define a variable field name e.g this time the field was call NPCDOE next time it may be called XYZ.
Saving Variable To Text File...
I currently have a variable being stored as objectname = obectname +object 1 + ";" and i want this to be stored to a text file and I want the variable which could end up like circle1;circle1;square1 to be written to 3 seperate lines. The ; should do this, except it is storing the thing with " " around it. Is there a way to save the variable without the quotes.
Extract Variable From Text File
I have an interesting question. I havea text file(.txt) and about halfway through it there a a variable (vr=XXXX). This file is the output of another program and I need to read that variable and assign it a new name.
Delete Text After A Variable In An Ini File
Hey everyone, I want to know if it is possible to delete any text that appears after a variable is defined in an ini file. For example:
ProgDir=C:Program FilesProgram Name
LastProfile=C:Program FilesProgram NameProfileUsername.txt
InstallDir=C:Program FilesProgram Name
In the example above I want to remove everything to the right of "LastProfile=", but I DO NOT want to remove anything else from the file including blank lines. Does anyone know how I could do this? If you could let me know it would be HUGELY appreciated. TIA!
BTW I tried using code that jcis posted, but it removes the entire line and any blank lines (The code was posted here: http://www.vbforums.com/showthread.p...ht=delete+line)
Possible To Create Variable Names W/ Variables?
Thanks for your help guys! I have another question
Is it possible to create names of variables with variables?
For example, I'm thinking of something like:
Dim Cstr("string" & variable) As Variant
However, this doesn't work. Is there some other syntax of method that I can use to do this?
Will, if this helps, I'm thinking of using this for a multidimentional array. Like:
Dim theBigArray() As Variant
For i=0 to something
Dim Cstr("string" & i)() As Variant
theBigArray(i)=Cstr("string" & i)()
For j=0 to something
Cstr("string" & i)(j)=j
Well this is the first time I've used multidimentional arrays so I don't even know if I'm using it right But thats basically what I'm trying to do.
Thanks in advance
Variable Names That Alter Within A Loop
I am trying to declare a variable within a loop so that its name increments on each cycle.
I have set a variable outside of the loop 'cyclingValue = 0',
but want to attach it to the end of a new variable name 'serv' to get a series of variables:
In my low capacity brain it would look something like:
<% do while ..............
DIM (serv+cyclingValue) = whatever
cyclingValue = cyclingValue +1
<% LOOP %>
....its the DIM line and particularly the bit that Iíve stupidly put in brackets that I cant figure.
Adding To Database Using Variable Names
I'm having trouble adding a new record by using INSERT INTO.
I made a new connection, sql string (and rs) as in Loquin's code below:
Dim cn as ADODB.Connection
Set cn = New ADODB.Connection
cn.Open strConnect ' strConnect contains the connection string...
strSQL = "Insert Into YourTableName (pk_ID, Item_No, Description) Values (17, 'PART-007', 'Left Hand FooBar Retainer Clip')
set cn = Nothing
But the problem is, the values that will be sent to the database are variables. I have written the SQL string like this:
sqlstring="insert into contacts values(' " & var1 & " ',' " & var2 & " ',)"
Actually, there are about a dozen variables... but can anyone see a syntax error here? Easy to do I know, given all the quote marks and ampersands, and some variables are zero-length strings. That's not the problem - I am getting an error message saying "Syntax error in INSERT INTO statement".
I am sure the variables themselves are written OK. My main worry is with the very beginning and end of the SQL string. It starts and ends with double-quotes, which I think is kosher. What about the rest?
Linking Variable Names For Output
I am trying to link 2 variables together with text to display in a "save as" input box. How can I properly link the "uid" and "currentdate" variable names with default text in between? I would like it to read "uid_currentdate_1.doc"
This is the syntax that I am using :
Default = & uid "_ " & current_date "_1.doc" ' Set default.
' Display message, title, and default value.
Basic Question About Variable Names
It must be very easy but I am not very familiar with VB. I can do this easily in Stata:
Public g1, g2, g3 as Integer
For I=1 to 3
g`I' = I*10
This obviously wouldn't work in VB since there is no `I' option... Basically, when I = 1, g`I' is supposed to be g1.
When I = 2, g`I' is supposed to bve g2, and so on.
Is there any way to implement this in Visual Basic?
Thank you so much for the help.
Storing Variable Names In A String
I am having a string/variable problem, which I imagine is straight forward,
but I have not been able to solve at this stage.
I am storing an sql query in an access database where the text(query)
contains a mixture of text and variables that will be populated with values
when the query is used in the app...for example
"Select" & sqlfields & " from " & thmeDataset & " where " & sqlsearchfld & "
in (" & SelListStr & ");"
anyway , the problem that I am having, is that when I read the sql query in
(in VB 6) it is all recognised as a string, so the variable names are not
replaced with the values that they hold. if I were to assign the above query
to a text variable inside the vb code, then each variable would be replaced
with the associated value...
do any of you know of a way to get around this? Do I need to make a
procedure which passes the query in and figures out what is a variable and
what is not?
thanks in advance,
Phil Bright BSc(GIS)
Secretariat of the Pacific Community (SPC)
B.P.D5, Noumea Cedex 98848
Phone (687) 26.20.00 ext(226)
Fax (687) 26.38.18
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.380 / Virus Database: 213 - Release Date: 24/07/2002
Variable Names Change When Saving
We have several developers working on the same VB code. When one user makes a line change VB will automatically change several variable names.
For example moduleName becomes ModuleName or vice versa.
From what I understand VB will find the first variable with that name and change the case on another variable with that name. The problem is that the variable names keep getting switched back and forth every time a different developer commits there changes to the code base. this means that a one line code change will actually change 200 lines of code making tracking changes rather cumbersome.
Is there anyway to control this behavior so all developers will have the same variable names.
Open File And Grab All Text As A Variable
I am wondering if I create a log file using the PRINT method rather than WRITE can I open that file again and grab all the text as one variable so that I could append it to the end of another file. If so how would this best be done.
Check The Availability Variable In Text File
How to check whether a variable is already in a text file..
my system will receive one variable and keep it in text file..but i want to prevent duplicate save the same variable..
example of text file:
for example if in the text file already have "KP7053M4DF" and the system receive "KP7053M4DF".the error msg will come out.
Can anyone show me the sample of vb code.
Multi-line Text File As Variable
How do i store a multi-line text file as a variable. right now i have
Dim aDocument as String
Open "C: est.txt" For Input As #1
Line Input #1, aDocument