Memory Access Violation

Started by windman, April 09, 2018, 21:04:53

Previous topic - Next topic

windman

What is wrong with the code?

While MilliSecs()-ST<3500
LL=Rand(80,644)
For H=1 To LL:C=Rand(32,126)
S$=S$+Chr$(C)
Next
WriteLine(FH1,S$);5:Print S$:HALT
S$=""
Wend
;Text 20,20,"FW: "+LN:VWait:Flip:Cls
CloseFile(FH1)


It looks right to me but continually get the Memory Access Violation error

Pakz

Did you create the file? I think you need to open a file before it can be written to.

STEVIE G

#2
Quote from: windman on April 09, 2018, 21:04:53
What is wrong with the code?

While MilliSecs()-ST<3500
LL=Rand(80,644)
For H=1 To LL:C=Rand(32,126)
S$=S$+Chr$(C)
Next
WriteLine(FH1,S$);5:Print S$:HALT
S$=""
Wend
;Text 20,20,"FW: "+LN:VWait:Flip:Cls
CloseFile(FH1)


It looks right to me but continually get the Memory Access Violation error

Compile in debug mode for a better idea.  Looks like you aren't creating the file to write to unless this part of the code is missing?   i.e. FH1 = WriteFile( Filename )

There's also no such command in B3d as HALT, so assume it's your own.  What does that do?

p.s. Flip (true by default) automatically does a Vwait so no need for a separate command unless you are using Flip false.

windman


FH1=WriteFile("C:FN$+".TXT"):LN=LN+1

While MilliSecs()-ST<3500
LL=Rand(80,644)
For H=1 To LL:C=Rand(32,126)
S$=S$+Chr$(C)
Next
WriteLine(FH1,S$);5:Print S$:HALT
S$=""
Wend
CloseFile(FH1)


Sorry about that.
Here's the top portion before dropping into the loop

windman

I found the problem. The variable FH1 gets reset to zero after it enters the while loop for some reason.
I tried GLOBAL but it changes nothing.

Any Suggestions?

Matty

Your writefile expression is completely wrong - unmatched quotes.

windman

I fixed that and still get an error.
Might be the compiler

windman

While Not KeyDown(1)

ST=MilliSecs()
FN$=RFN():
LN=LN+1

If MilliSecs()-ST<3500
FH1=WriteFile("C:"+FN$+".TXT")
LL=Rand(80,644)
For H=1 To LL:
C=Rand(32,126)
S$=S$+Chr$(C)
Next
WriteLine(FH1,S$)
S$=""
EndIf

CloseFile(FH1)

Wend

windman

I found the problem. It was another part of the code.
The portion that was generating the name was at times generating some special character that windows would not allow.
The program would then return a zero for the file handle because of windows.

RemiD

Hence the usefulness of DebugLog()... (to check how the strings that you generate with parts, look like)

Matty

I'm surprised it works without a backslash after the c colon.

windman

#11
QuoteHence the usefulness of DebugLog()... (to check how the strings that you generate with parts, look like)

Actually the Debug log never indicated that the code generating the name was giving the error. The Debug log showed the:

WriteLine(FH1,S$)

instruction to be the error. But that was because the:

FH1=WriteFile("C:"+FN$+".TXT")

had an illegal character that was generated in the name, within FN$ making FH1 return a value of zero.
I found that there are 8 characters that cannot be used in a filename. So I wrote a different routine that generated a valid name excluding those characters.
The Microsoft web page also mentions that Unicode characters are allowed but I am lost at how to get them to show in the name algorithm.

QuoteI'm surprised it works without a backslash after the c colon.

The BB compiler allows that and it is convenient. The compiler also allows some interesting nested logical functions that, though confusing, can abbreviate the source code that you write.

RemiD

#12
Quote
Actually the Debug log never indicated that the code generating the name was giving the error.
what i meant was using debuglog to display the string value made of string parts, something like :


PathAndFilename$ = "C:"+FN$+".TXT"
debuglog(PathAndFilename)
FH1=WriteFile(PathAndFilename)

windman

Oh that

I never knew that I could do that inside of BB.
thanks for the tip

3DzForMe

I created a Read Write Debug function to try and get to the bottom of some 'path' hiccups, Windows is very fickle when it comes to paths depending upon which OS you're using.
:-X
BLitz3D, IDEal, AGK Studio, BMax, Java Code, Cerberus
Recent Hardware: Dell Laptop
Oldest Hardware: Commodore Amiga 1200 with 1084S Monitor & Blitz Basic 2.1