|
|
|||||||||
|
|||||||||
|
|||||||||
| |
||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
Substrings
I have some code that is reading an NMEA string from a GPS UNit. I am writing the String to a variable and then parsing it out into an array, of which, I am grabbing a few sections.
There is one problem that is arising when I collect the data. THe decimal point is being placed in the incorrect location of the variable. I wrote the below code to place the decimal point in the correct location, but for some reason I am getting an error (see red text in teh code).....Any thoughts. If I use the code from CODE_2 below....it works but again the decimal is in the wrong location...Is my syntax wrong... Im getting an error "Invalid Qualifer"...I dont know what that error is refering to.....THANKS I AM USING MICROSFOT ACCESS VBA CODE: Function Test_Click2() Dim a As String, aItems() As String Dim i As Integer Dim NMEA2 As String NMEA2 = NMEAString3 'Sets the Variable from MSComm7 to NMEA aItems = Split(NMEA2, ",") 'This splits by a comma. Change if needed"," i = 0 For i = 0 To UBound(aItems) 'Sets i to the Upper Bound of sItems or the NMEA String NewCoords2 = Trim(aItems(i)) 'Trims the spaces on either side of the string If i = 2 Then Dim TestX As String ' Here I am attempting to split the LatLong String TestX = NewCoords2 Xcoord_A = TestX.Substring(0, 2) 'Grab the first two characters Xcoord_A = Xcoord_A & "." & TestX.Substring(2, 10) 'Reuse the first two char, concantonate the "." and the remainder of the string Xcoord2 = Xcoord_A CODE_2: Dim s As String, sItems() As String Dim i As Integer Dim NMEA As String NMEA = NMEAString 'Sets the Variable from MSComm7 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 Xcoord2 = NewCoords |
|
#2
|
|||
|
|||
|
An additional thought....I have the variable set as global
Dim Xcoord_A As String I cant figure out what "Invalid Qualifer" is refering to..... THanks,,, |
|
#3
|
|||
|
|||
|
First, VB strings don't have a substring method. Use mid(), InStr(), and other string functions. Access VBA has online help that will show you proper syntax for all your VBA coding.
And right after you define TestX on the next line you are trying to set it to some object?
__________________
====== Doug G ====== I didn't attend the funeral, but I sent a nice letter saying I approved of it. --Mark Twain |
|
#4
|
|||
|
|||
|
I fixed my problem....just wanted to give you all that read this forum entry the fix.....the problem was two fold....
1. The value being passed to the Variable was not a string, while I had the Varaible "Dim As String". I used CStr(Varaible) to set the variable to a string. SEE IN RED BELOW 2. I was using "SubString" to grab a portion of a word returned from an Array. I changed this by using either: Left(variable, X) with x being the number of digits to read from left Right(variable, X) Mid(variable, 1,2) CODE: Function Test_Click2() Dim a As String, aItems() As String Dim i As Integer Dim NMEA2 As String NMEA2 = NMEAString3 'Sets the Variable from MSComm7 to NMEA aItems = Split(NMEA2, ",") 'This splits by a comma. Change if needed"," i = 0 For i = 0 To UBound(aItems) 'Sets i to the Upper Bound of sItems or the NMEA String NewCoords = Trim(aItems(i)) 'Trims the spaces on either side of the string If i = 2 Then Dim TestX As String 'Here I am attempting to split the LatLong String Dim XCoord_A As String 'Dim Xcoord As String Xcoord = "" XCoord_A = NewCoords XCoord_String = CStr(XCoord_A) If XCoord_String <> "" Then TestX = Mid(XCoord_String, 1, 2) 'Grab the first two characters TestX = TestX & "." & Mid(XCoord_String, 3, 2) 'Reuse the first two char, concantonate the "." and the remainder of the string TestX = TestX & Mid(XCoord_String, 6, 10) Xcoord = TestX MsgBox Xcoord End If |
|
#5
|
|||
|
|||
|
Thanks for posting your solution.
|
![]() |
| Viewing: ASP Free Forums > Programming > Visual Basic Programming > Substrings |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|