|
|
|||||||||
|
|||||||||
|
|||||||||
| |
||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
Write to Variable
I have some code that is reading a string from the CommPort. I have that string writing to a variable. The string is comma delimeted so I have code in place to break it apart by the commas. I then write it to a counter and spit back all the sections of the string.
What I want to do is write each section to a variable...anyone have any thoughts? See Code example below.....I would have to replace the "For iCounter" statement with code to place each section into variables. I dont know the syntax I should use.... I AM IN ACCESS VBA..... THanks NMEAString is a global variable that is storing the string pushed to the CommPort...... CODE: Dim s As String, sItems() As String Dim iCounter As Integer Dim NMEA As String NMEA = NMEAString sItems = Split(NMEA, ",") 'This splits by a comma. Change if needed"," For iCounter = LBound(sItems) To UBound(sItems) MsgBox sItems(iCounter) Next |
|
#2
|
|||
|
|||
|
You could always do something like
[code] var1 = sitems(0) var2 = sitems(1) ' etc [code]
__________________
====== Doug G ====== I didn't attend the funeral, but I sent a nice letter saying I approved of it. --Mark Twain |
|
#3
|
||||
|
||||
|
what result ur getting........pls post
|
|
#4
|
|||
|
|||
|
Write to Variable
Question is there a way I can place my code in this forum without it placing it all on the left margin....
the code looks very sloppy and makes it hard to read....there are comments after most lines so ignore them.....if there was a way I could retain the format it would be far easier to read. I actually hacked away at this last night and got it working....this is what I coded....I thank you all for your help...I am really developing my skills with all of your help...I hope to repay the favor with helping others someday on this site..... Note For anyone looking at this....I will be posting my entire code for pulling the NMEA String from a Trimble Unit and bringing it into Access. In its raw for there are a couple buttons... Retrieve Button - Gets the string adn displays it in a text box Get String Button - grabs teh same string, splits it by comma, parses the string and write each wated section to seperate variables that can be grabbed by any portion of the form. I THANK YOU ALL FOR YOUR HELP...... CODE FOR SPLITTING AND SETTING STRING SECTIONS TO VARIABLES: Public Sub GetString_Click() Dim s As String, sItems() As String Dim i As Integer Dim NMEA As String NMEA = NMEAString 'Sets the Variable from MSComm6 to NMEA sItems = Split(NMEA, ",") 'This splits by a comma. Change if needed"," i = 0 For i = 0 To UBound(sItems) 'Sets i to the Upper Bound of sItems or the NMEA String NewCoords = Trim(sItems(i)) 'Trims the spaces on either side of the string If i = 2 Then 'Looks for teh 6th word in the string X = NewCoords 'Sets the 6th word to the variable First1 ElseIf i = 3 Then LongHem = NewCoords ElseIf i = 4 Then Y = NewCoords ElseIf i = 5 Then LatHem = NewCoords ElseIf i = 9 Then Elev = NewCoords ElseIf i = 10 Then ElevUnit = NewCoords End If Next 'Walks through the string MsgBox X 'Returns the variables in a message box MsgBox LongHem MsgBox Y MsgBox LatHem MsgBox Elev MsgBox ElevUnit End Sub |
|
#5
|
|||
|
|||
|
Quote:
Look at the forum FAQ's. There is a section on "forum codes" like [ code ] [ /code ] (without the spaces in the brackets btw) There are many other handy forum codes you can use in your posts. |
![]() |
| Viewing: ASP Free Forums > Programming > Visual Basic Programming > Write to Variable |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|