Visual Basic Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
 
User Name:
Password:
Remember me
Go Back   ASP Free ForumsProgrammingVisual Basic Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread ASP Free Forums Sponsor:
  #1  
Old September 12th, 2005, 05:02 PM
Jaykappy Jaykappy is offline
Contributing User
ASP Free Novice (500 - 999 posts)
 
Join Date: Feb 2005
Posts: 739 Jaykappy User rank is Sergeant (500 - 2000 Reputation Level)Jaykappy User rank is Sergeant (500 - 2000 Reputation Level)Jaykappy User rank is Sergeant (500 - 2000 Reputation Level)Jaykappy User rank is Sergeant (500 - 2000 Reputation Level)Jaykappy User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 5 Days 9 h 12 m 28 sec
Reputation Power: 22
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

Reply With Quote
  #2  
Old September 12th, 2005, 08:39 PM
Jaykappy Jaykappy is offline
Contributing User
ASP Free Novice (500 - 999 posts)
 
Join Date: Feb 2005
Posts: 739 Jaykappy User rank is Sergeant (500 - 2000 Reputation Level)Jaykappy User rank is Sergeant (500 - 2000 Reputation Level)Jaykappy User rank is Sergeant (500 - 2000 Reputation Level)Jaykappy User rank is Sergeant (500 - 2000 Reputation Level)Jaykappy User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 5 Days 9 h 12 m 28 sec
Reputation Power: 22
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,,,

Reply With Quote
  #3  
Old September 13th, 2005, 10:22 PM
Doug G Doug G is offline
Grumpier Old Moderator
ASP Free God 11th Plane (10000 - 10499 posts)
 
Join Date: Sep 2003
Posts: 10,143 Doug G User rank is First Lieutenant (10000 - 20000 Reputation Level)Doug G User rank is First Lieutenant (10000 - 20000 Reputation Level)Doug G User rank is First Lieutenant (10000 - 20000 Reputation Level)Doug G User rank is First Lieutenant (10000 - 20000 Reputation Level)Doug G User rank is First Lieutenant (10000 - 20000 Reputation Level)Doug G User rank is First Lieutenant (10000 - 20000 Reputation Level)Doug G User rank is First Lieutenant (10000 - 20000 Reputation Level)Doug G User rank is First Lieutenant (10000 - 20000 Reputation Level) 
Time spent in forums: 3 Weeks 4 Days 23 h 19 m 36 sec
Reputation Power: 181
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

Reply With Quote
  #4  
Old September 14th, 2005, 09:21 AM
Jaykappy Jaykappy is offline
Contributing User
ASP Free Novice (500 - 999 posts)
 
Join Date: Feb 2005
Posts: 739 Jaykappy User rank is Sergeant (500 - 2000 Reputation Level)Jaykappy User rank is Sergeant (500 - 2000 Reputation Level)Jaykappy User rank is Sergeant (500 - 2000 Reputation Level)Jaykappy User rank is Sergeant (500 - 2000 Reputation Level)Jaykappy User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 5 Days 9 h 12 m 28 sec
Reputation Power: 22
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

Reply With Quote
  #5  
Old September 14th, 2005, 05:04 PM
Doug G Doug G is offline
Grumpier Old Moderator
ASP Free God 11th Plane (10000 - 10499 posts)
 
Join Date: Sep 2003
Posts: 10,143 Doug G User rank is First Lieutenant (10000 - 20000 Reputation Level)Doug G User rank is First Lieutenant (10000 - 20000 Reputation Level)Doug G User rank is First Lieutenant (10000 - 20000 Reputation Level)Doug G User rank is First Lieutenant (10000 - 20000 Reputation Level)Doug G User rank is First Lieutenant (10000 - 20000 Reputation Level)Doug G User rank is First Lieutenant (10000 - 20000 Reputation Level)Doug G User rank is First Lieutenant (10000 - 20000 Reputation Level)Doug G User rank is First Lieutenant (10000 - 20000 Reputation Level) 
Time spent in forums: 3 Weeks 4 Days 23 h 19 m 36 sec
Reputation Power: 181
Thanks for posting your solution.

Reply With Quote
Reply

Viewing: ASP Free ForumsProgrammingVisual Basic Programming > Substrings


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 2 hosted by Hostway
Stay green...Green IT