Download the free trial version
Basic4android Video
Features
Tutorials and manuals
Showcase
Screenshots

Go Back   Android Development Forum - Basic4android > Basic4ppc (Windows Mobile) > Questions (Windows Mobile)
Documentation Wiki Register Members List B4P Search Today's Posts Mark Forums Read

Questions (Windows Mobile) Post any question regarding Basic4ppc.

Please take a look at this code

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 09-27-2009, 12:04 AM
Basic4ppc Veteran
 
Join Date: Sep 2009
Location: South Jordan, Utah
Posts: 237
Send a message via Skype™ to jschuchert
Default Please take a look at this code

Below are 5 lines of comma-delimited text which I wish to manipulate with the code below it. The lines of text constitute the file 'strfilename'

Quote:
1,1000,1000,none
2,1027.699,1030.228,none
3,5000,5000,iron rod
4,993.547,6987.254,none
Code:
Sub Globals
    
'Declare the global variables here.
    Public dblnorth1,dbleast1,dblndiff,dblediff,dblbearing,dblbearingdms
    Public dblnorth2,dbleast2
    
Dim firstpt,secondpt
    
Dim coord(4)  '<font color="red">array for variable 'coord'</font>
     radian=cPI/180
     radianreverse=
180/cPI
End Sub


Sub startinverse8(strbearing)
FileClose(c)
FileOpen(c, main.strfilename,cRead)
pintcntr = StrIndexOf(strBearing, 
"*",0) <font color="red">strbearing=1*2</font>
firstpt = SubString(strBearing, 
0, pintcntr)
secondpt = SubString(strBearing, pintcntr+
1,StrLength(strbearing)-pintcntr)
lineoftext=
""
Do Until lineoftext = EOF
lineoftext=FileRead(c)   
'<font color="red"> reads each line consecutively</font>
coord()=StrSplit(lineoftext,",")
If coord(0)= secondpt Then  '<font color="red"> first character in the line of text </font>
dblnorth2=coord(1
dbleast2=coord(
2)
Exit    '<font color="red"> exit the loop when coord(0)=2 (second pt)</font>
End If
Loop
-
-
-
I have verified that the variable 'secondpt' has the value of 2 (I set a break point and observed it)

Here is the issue: The program loops through the lines of text and parses the first character (coord(0)) in the order it should but WILL NOT execute the next line of code when it compares 'secondpt' with 2. If I use the actual number 2, then it works. It has no problem with 'firstpt' which is 1 ( I didn't include the code for that). I looked for a 'trim' or 'strtrim' thinking that maybe a leading space was causing the problem but couldn't find one. My app will be using this method a lot so I need to solve the problem. Thanks for all the past support your have given.

Jim
Reply With Quote
  #2 (permalink)  
Old 09-27-2009, 02:12 AM
Basic4ppc Veteran
 
Join Date: Sep 2009
Location: South Jordan, Utah
Posts: 237
Send a message via Skype™ to jschuchert
Default

I found solution. If I use "int" before the variable, it works. Apparently this is the only type changing keyword. I thought everything was a variant and the program would 'type' it within its context.
Reply With Quote
  #3 (permalink)  
Old 09-27-2009, 09:35 AM
agraham's Avatar
Basic4ppc Expert
 
Join Date: Jul 2007
Location: Cheshire, UK
Posts: 6,072
Awards Showcase
Innovator medal Beta Tester Forum Contributer 
Total Awards: 3
Default

It is not a typing issue, the real problem is an "off by one" here
Code:
secondpt = SubString(strBearing, pintcntr+1,StrLength(strbearing)-pintcntr)
You are asking for one more character than exists in the string so SubString is padding it with an extra space at the end. The If is doing a string comparison between "2" and "2 " and failing.

Your Int() is transforming "2 " to "2", forcing any arithmetic operation will in fact make it work like "secondpt * 1". The real fix is to get the length right in the first place.
Code:
secondpt = SubString(strBearing, pintcntr+1,StrLength(strbearing)-pintcntr<font color="Red"><b>-1</b></font>)
__________________
Sorry, but I don't answer questions by PM or email.
Please post your queries in the forum.
Reply With Quote
  #4 (permalink)  
Old 09-27-2009, 04:13 PM
Basic4ppc Veteran
 
Join Date: Sep 2009
Location: South Jordan, Utah
Posts: 237
Send a message via Skype™ to jschuchert
Default

Yes, that is true and I think the '0' index was confusing me. Here was my thinking: pintcntr=2 (because the '*' is the second character) but with 0 as the index it is 1. (too much use of "mid" in other programs) Strlength(strbearing) was 3 ... pintcntr+1 (2+1) was 3 also and "strlength(strbearing) - pintcntr(2)" = 1...hence secondpt would be the value of "2" if I had used the correct index.

Your "off by one" is accurate and a good catch. After your analysis, I did some checking on the lengths of points 1 and 2 when I assigned them by the substring method earlier and found the same problem with "2". As a matter of fact, the length of strbearing was 4 (1*2 ) because of that. Thanks again for your eagle eye and great help. I really value your opinions and expertise.

Jim
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

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
Trackbacks are Off
Pingbacks are Off
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
use vb6 code wm.chatman Questions (Windows Mobile) 7 03-27-2009 09:01 PM
Help With Code Please cdeane Questions (Windows Mobile) 5 01-19-2009 08:55 PM
help with code twisted Questions (Windows Mobile) 10 01-09-2009 06:27 PM
Add Code giannimaione Questions (Windows Mobile) 5 06-01-2008 06:03 PM
Help with code cdeane Questions (Windows Mobile) 9 09-22-2007 04:30 PM


All times are GMT. The time now is 10:29 AM.


Powered by vBulletin® Version 3.6.12
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0