is it possible to pass variables from a textbox in visual basic?
is it possible to pass variables from a textbox in visual basic?
i am trying to pass a variable from a textbox. eg this is what is contained in a textbox
Hallo " & !Name & ", your current balance is " & !amount & ". please pay this amount to avoid disconnection!!! Customer Service.
the variables contained in the text box are !name and !amount
the app should be able to tell me what is contained in the field amount and name.
Re: is it possible to pass variables from a textbox in visual basic?
Pass the variables from a textbox that is *where* exactly?
If it's your form, it is simple enough to do this...it's fundamental programming :-P
Re: is it possible to pass variables from a textbox in visual basic?
Yes from my form. can u show me how to do this. below is the code am using but it doesnt pull the variables. it just returns the same string that is contained in the textbox
VB Code:
Set SQLINTERGRATION = New ADODB.Recordset
Dim sTemp As String
If txtsql.Text = "" Then
MsgBox "Please specify the sql string to be executed", vbInformation, "Error"
Exit Sub
End If
SQLINTERGRATION.Open "" & txtsql.Text & "", gConnection, adOpenDynamic, adLockOptimistic
Set DGINtergartion.DataSource = SQLINTERGRATION
With SQLINTERGRATION
Do While .EOF = False
sTemp = txtsqlmessage
MsgBox sTemp
'...
.MoveNext
Loop
End With
Re: is it possible to pass variables from a textbox in visual basic?
The textbox has a .Text property. Call that.
BTW, ! is not allowed in variable or control names.
What context does this apply to?
Where do the name and amount come from? A database?
Re: is it possible to pass variables from a textbox in visual basic?
How do the variables get into the textbox? What is your query for that? (I see what you have in Post #3, but that doesn't look like it is doing anything.)
Re: is it possible to pass variables from a textbox in visual basic?
Quote:
What context does this apply to?
Where do the name and amount come from? A database?
name and amount are coming from a database.
This is what i am trying to achieve. a user types a custom message on a textbox where he has included the variables. My app then does a loop through the recordset a creates a customized message fro each record.
Re: is it possible to pass variables from a textbox in visual basic?
Ok. Then what is contained in txtSQL.Text?
Re: is it possible to pass variables from a textbox in visual basic?
So the variables are taken from the database...put into a textbox...
Now I am guessing that what you want is for the text in text1 (for instance) which says "Hallo !name, your current balance is !amount. please pay this amount to avoid disconnection!!! Customer Service." to be changed to replace !amount and "!name" with the actual name and amount.
If so, try "text2 = replace(text1,"!name",txtName)" and "text2 = replace(text2,"!amount",txtAmount)
Edit: Hack, I am guessing it's "Hallo " & !Name & ", your current balance is " & !amount & ". please pay this amount to avoid disconnection!!! Customer Service."
Re: is it possible to pass variables from a textbox in visual basic?
Hi Hack
Quote:
How do the variables get into the textbox? What is your query for that? (I see what you have in Post #3, but that doesn't look like it is doing anything.)
a user will type them in with a customised message. the query is also input by the user since my app is able to connect to any database. the user types in a query and the results are then put in a datagrid.
a message is then typed on a textbox including the variables. its kind of a mail merge..
Re: is it possible to pass variables from a textbox in visual basic?
Quote:
So the variables are taken from the database...put into a textbox...
the variables are not put into a text box. they are put into a datagrid and the user types the column heading preceeded by a ! to denote the variable. hope am not confusing you
Re: is it possible to pass variables from a textbox in visual basic?
I think that *basically* the function you need is replace...I describe how to use it above, but it's as simple as replace=(STRING,FINDTHIS,REPLACEWITHTHIS)
So if you had debug.print replace("abcdefghijk","abc,"ABC") it would return "ABCdefghijk"...so it replaces "abc" with "ABC"...sound as simple as ABC to you now? :-)
Re: is it possible to pass variables from a textbox in visual basic?
leaving it for the user to type the query in sounds like an error waiting to happen
Re: is it possible to pass variables from a textbox in visual basic?
i only allow SELECT statements to be typed. Inserts Drops alters are disabled. n way only an admin will be using the system.
below is a screenshot of the app.
Screenshot
hope this will be more clearer on the predicament i am facing?
Re: is it possible to pass variables from a textbox in visual basic?
So you need to take a string message such as "Hello !name, your current balance is !amount", which you get from the user via a textbox, and replace the ![variable] parts with the value of the column with the same name in the datagrid, and do that for each row in the datagrid, creating many results?
Re: is it possible to pass variables from a textbox in visual basic?
Thats exactly what i want to achieve. is it possible or is there a simpler way to do this.
Re: is it possible to pass variables from a textbox in visual basic?
Pseudo-code - since I haven't used VB6 in a while and I never used the DataGrid...
VB Code:
Dim strResult As String
for each row in the data grid
for each column in the row
replace "!" & column name in strResult with value from column
next
'do something with strResult which now has all the values from current row
next