Strange Problem

BlitzMax Forums/BlitzMax Beginners Area/Strange Problem

wmaass(Posted 2009) [#1]
I have a little application that I wrote that works fine on every PC I have tested accept for my bosses laptop. I did a bit of trouble shooting and this bit of code causes the program not to run - you double click on the icon and see the hour glass for a split second and nada. Any idea what a simple Select statement would do this?

	Select go$
		Case "http://www.aboutgolf.com/fitter/start"
			ballspeed=getspeed()
			If ballspeed=0
				HtmlViewGo htmlview,"http://www.aboutgolf.com/fitter/getspeed.html"
				go$ = "null"
				Else
				HtmlViewGo htmlview,"http://www.aboutgolf.com/fitter/ballstofit.php?tball=" + ballspeed
				go$ = "null"
			EndIf
			
		Case "http://www.aboutgolf.com/fitter/all"
			balltype=1
			HtmlViewGo htmlview,"http://www.aboutgolf.com/fitter/price.html"
			go$ = "null"
			
		Case "http://www.aboutgolf.com/fitter/women"
			balltype=2
			HtmlViewGo htmlview,"http://www.aboutgolf.com/fitter/price.html"
			go$ = "null"
			
		Case "http://www.aboutgolf.com/fitter/a"
			price$="a"
			HtmlViewGo htmlview,"http://www.aboutgolf.com/fitter/rate.html"
			go$ = "null"
			
		Case "http://www.aboutgolf.com/fitter/b"
			price$="b"
			HtmlViewGo htmlview,"http://www.aboutgolf.com/fitter/rate.html"
			go$ = "null"
			
		Case "http://www.aboutgolf.com/fitter/c"
			price$="c"
			HtmlViewGo htmlview,"http://www.aboutgolf.com/fitter/rate.html"
			go$ = "null"
			
		Case "http://www.aboutgolf.com/fitter/1"
			rating=1
			furl$="http://www.aboutgolf.com/fitter/result.php?bs=" + ballspeed + "&show=" + balltype + "&pr=" + price + "&rt=" + rating
			HtmlViewGo htmlview,furl$ 
			go$ = "null"
			
		Case "http://www.aboutgolf.com/fitter/2"
			rating=2
			furl$="http://www.aboutgolf.com/fitter/result.php?bs=" + ballspeed + "&show=" + balltype + "&pr=" + price + "&rt=" + rating
			HtmlViewGo htmlview,furl$ 
			go$ = "null"
			
		Case "http://www.aboutgolf.com/fitter/3"
			rating=3
			furl$="http://www.aboutgolf.com/fitter/result.php?bs=" + ballspeed + "&show=" + balltype + "&pr=" + price + "&rt=" + rating 
			HtmlViewGo htmlview,furl$
			go$ = "null"

			
		Case "http://www.aboutgolf.com/fitter/4"
			rating=4
			furl$="http://www.aboutgolf.com/fitter/result.php?bs=" + ballspeed + "&show=" + balltype + "&pr=" + price + "&rt=" + rating
			HtmlViewGo htmlview,furl$
			go$ = "null"
			
		Case "http://www.aboutgolf.com/fitter/5"
			rating=5
			furl$="http://www.aboutgolf.com/fitter/result.php?bs=" + ballspeed + "&show=" + balltype + "&pr=" + price + "&rt=" + rating 
			HtmlViewGo htmlview,furl$
			go$ = "null"
			
		Case "http://www.aboutgolf.com/fitter/new"
			HtmlViewGo htmlview,"http://www.aboutgolf.com/fitter/start.php"
			go$ = "null"
					
		Case "http://www.aboutgolf.com/fitter/114"
			ballspeed=114
			HtmlViewGo htmlview,"http://www.aboutgolf.com/fitter/ballstofit.html"
			go$ = "null"
		
		Case "http://www.aboutgolf.com/fitter/129"
			ballspeed=129
			HtmlViewGo htmlview,"http://www.aboutgolf.com/fitter/ballstofit.html"
			go$ = "null"
			
		Case "http://www.aboutgolf.com/fitter/130"
			ballspeed=130
			HtmlViewGo htmlview,"http://www.aboutgolf.com/fitter/ballstofit.html"
			go$ = "null"
		
	End Select



GfK(Posted 2009) [#2]
You should stick a Default in your Select block, and throw a runtime error from there containing [what I assume to be] the commandline which is being passed to your app. The end of your Select block should look like this:

        Default
                RuntimeError go$
End Select

Get your boss to run it again. If, for some reason none of the Case conditions are met, it'll throw an error containing the string it was trying to parse.


Brucey(Posted 2009) [#3]
most probably an issue with HtmlViewGo.
Perhaps the version of IE on that computer isn't playing nicely.

Maybe try a small test app with an htmlview, see if that works?


wmaass(Posted 2009) [#4]
Brucey,

I tried the sample for htmlview from the online docs and it works fine. So it must be something with the Select statment.

Gfk, great idea, will try now.


wmaass(Posted 2009) [#5]
Even stranger, with the Default set as Gfk suggests I get an unhandled exception right away and the program won't run on my pc, even though the program WILL run without the Default set for the Select statement. On my bosses laptop (IBM Thinkpad) it still doesn't even open, or show the unhandled exception.

I think I'm going to redo this thing anyhow. The htmlview is handy and for the most part the application works but it isn’t necessary for this.

On that note I have a question:

What this program does is it reads a file on the local machine to find out how fast a golf ball was hit. With that info and some other user definable parameters the program queries a remote MySQL database to find the best golf ball for the ball speed and user parameters. I want to make the program run entirely locally and not rely on the online MySQL database. What is the best way to store and retrieve the golf balls? I'm thinking or Data. Thoughts?


Brucey(Posted 2009) [#6]
An SQLite database?
You can use mostly the same queries then.


wmaass(Posted 2009) [#7]
Oh wow. Just goes to show how dense I can be. Being able to use the same queries is ideal. I had not realized that SQLite was self contained/serverless.


Brucey(Posted 2009) [#8]
Aye :-)

The engine compiles into your app.
The database is a file.


wmaass(Posted 2009) [#9]
And how cool of you to have a module ready to go!


Brucey(Posted 2009) [#10]
If you were using my mySQL module, you shouldn't have much code to change - the loaddatabase() call and DDL functions if you have any. (ddl - like create table etc).


wmaass(Posted 2009) [#11]
I was not using that but there wasn't a whole lot to the application, database anyway so I can get this thing hammered out pretty fast.


Brucey(Posted 2009) [#12]
Well, give me a shout if you have any issues.


wmaass(Posted 2009) [#13]
Will do. Brucey you are a legend.


xlsior(Posted 2009) [#14]
Case in point:



wmaass(Posted 2009) [#15]
Ok, after rebuilding the application to use a SQLite with a local db I am still not getting this to run on my bosses laptop. I managed to also reproduce the problem on another computer in my office. I installed BMax on this computer to debug it and here is what seems to be the problem:

This line from the function below is causing an error, specifically an unhandled exeption: attempt to index an array beyond the array limit.

Any idea why this works on most computers I have access to but not some?

Local tempvel:String = t$[5]


And the function...

Function getballspeed:Int()

Local v:Float
Local mps:Float
Local metersperhour:Float
Local mph:Int
Local s:String

	Local file:TStream = ReadFile("C:\Program Files\Friendly Software\World Tours Golf\SaveShot\--LastShot--.ss2")
	
	If file

		'get to the right line and read it into s$
		For Local r:Int = 1 To 47
			s = ReadLine(file)
		Next
	
		'close the stream
		CloseStream( file )

		'this is the string I want out of lastshot.ss2 on line 47
		'Local s$ = "4.71238899230957030000e+000 4.71238899230957030000e+000 5.50000038146972660000e+001 4.00000000000000000000e+001 4.71238899230957030000e+000 7.50000000000000000000e+001 8.50000000000000000000e+000 "

		'split the elements by the spaces so that I can get after the velocity
		Local t$[] = s.split(" ")

		'get element 5 which is the velocity expressed in mps
		Local tempvel:String = t$[5]
				
		Local trimvel:String = Left:String(tempvel, 5)
		
		'convert the string element to a float
		v = trimvel.ToFloat()
				
		mps = v * 10
		
		'figure out the meters per hour
		metersperhour = ((mps * 60) * 60)

		'figure out the miles per hour which is meters per hour / meters in a mile
		mph = metersperhour / 1609.344

		Return mph
	
	Else
		Return 0
	EndIf
	
End Function



Brucey(Posted 2009) [#16]
One question :
		For Local r:Int = 1 To 47
			s = ReadLine(file)
		Next

How do you know that is the correct line?
Always?


If the size of your string array can change, you may wish to rather test its length and report an error instead :
If t.length < 5 Then
   Notify "Problem with data : " + s
   End
End If


...Or fail silently and carry on...


wmaass(Posted 2009) [#17]
Hey Brucey,

While I was waiting for reply I checked into it and it looks like the file slightly different on the 2 computers that this does not work on - there is an extra line in it. So I will need to handle that. I could do that by using your tip about testing the array length.

How do I know I am reading the right file? Well I think I know because I am doing this before hand:

Local file:TStream = ReadFile("C:\Program Files\Friendly Software\World Tours Golf\SaveShot\--LastShot--.ss2")


But I think I know where you are going, I mean what if somebody was in a joking mood and put some other rubbish file in there named the same.


Brucey(Posted 2009) [#18]
Well, if it's your own file format, I suppose you will know what to expect in there :-)

You can always add a Log file to your app (if you want to report stuff to yourself in the background). You might enable it with a flag or option. Logging interesting facts during a program run can help to uncover issues.
Of course, adding logging everywhere can be a pain if your app is already quite large. (one of the things to think about in the early stages of development).

But try outputting the line/String of the file that has the error - you'll see immediately what the text was - and if it was the text you were expecting. If not, your file is obviously different.

Code defensively.
Any time an external source is used for some kind of input (be it a file, or someone entering data), there is a chance you will receive data that is out of the range you expect.
So, expect the unexpected... and try to handle those cases - like checking the size of your Split array...

:o)