Please use this Board for QBasic related requests ( file research, programming, etc.)
Moderators:Administrator, Global Moderator
-
Hive
I Need Help (Probably with write to or open file)
Post
by Hive » Wed Jun 29, 2005 11:39 am
I don't why it's doing this & it's racking my brain figuring it out but here is the cod I wrote.
I want it so that when the letters AAAA count up to ZZZZ it will write into a text file & new text file every 500kb. I figure swallow my pride & ask you people.
Here is the code.
Code: Select all
Declare Function Increase$ (Lett As String)
' You start off with AAAA
Dim Letters As String
Letters = "AAAA"
Open "C:\My Documents\letters.txt" For Output As #1
Do
Print #1, Letters
Letters = Increase$(Letters)
Loop Until Letters = "AAAA" 'it gets AAAA again after ZZZZ (but isn't printed)
Close
End
Function Increase$ (Lett As String)
Dim RetStr As String
Dim position As Integer, flipped As Integer
RetStr = Lett
flipped = 0
position = 1
Do
' reset flag
flipped = 0
' increase the letter at specified position
If Mid$(RetStr, position, 1) = "Z" Then
Mid$(RetStr, position, 1) = "A"
flipped = -1
position = position + 1
Else
Mid$(RetStr, position, 1) = Chr$(Asc(Mid$(RetStr, position, 1)) + 1)
End If
Loop Until Not(flipped) Or position = Len(RetStr) + 1
Increase$ = RetStr
End Function
in the Open "C:\My Documents\letters.txt" For Output As #1 column when it keeps telling me there is a path error but I'm pretty sure that's the right path. If I just put the "letters.txt" & hit run a black screen comes up for an about 10 seconds then it tells me to hit continue which when I check the file it supposed to write to after, nothing in it.
I hope this wasn't to long for you people, thank you[/code]
-
Mac
- Full Member
- Posts:48
- Joined:Wed Jun 29, 2005 2:01 am
-
Contact:
Post
by Mac » Thu Jun 30, 2005 6:53 pm
QBasic can only write to files with 8-character or less names
c:\abc\defghijk\m\happy.txt is a legal name
c:\My Documents\happy.txt is not
Mac
The QBasic Forum
http://www.network54.com/Forum/13959
-
Buff1
Post
by Buff1 » Fri Jul 01, 2005 8:26 am
DECLARE FUNCTION Increase$ (Lett AS STRING)
' You start off with AAAA
DIM Letters AS STRING
Letters = "AAAA"
OPEN "C:\letters.txt" FOR OUTPUT AS #1
DO
PRINT #1, Letters
Letters = Increase$(Letters)
LOOP UNTIL Letters = "AAAA" 'it gets AAAA again after ZZZZ (but isn't printed)
CLOSE
END
FUNCTION Increase$ (Lett AS STRING)
test$ = MID$(Lett, 1, 1)
VALUE% = ASC(test$)
IF VALUE% >= ASC("Z") THEN VALUE% = ASC("A") ELSE VALUE% = VALUE% + 1
retval$ = STRING$(4, CHR$(VALUE%))
Increase$ = retval$
END FUNCTION
-
Mac
- Full Member
- Posts:48
- Joined:Wed Jun 29, 2005 2:01 am
-
Contact:
Post
by Mac » Fri Jul 01, 2005 1:23 pm
I would suggest OPEN "scrn:" when first debugging. That way all output comes to the screen immediately and you don't have to go read files to see if your program is working.
Below is a version that is marginally faster.
Code: Select all
OPEN "scrn:" FOR OUTPUT AS #1
DEFINT I
CONST A = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
FOR I1 = 1 TO 26
C1$ = MID$(A, I1, 1)
FOR I2 = 1 TO 26
C2$ = MID$(A, I2, 1)
FOR I3 = 1 TO 26
C3$ = MID$(A, I3, 1)
FOR I4 = 1 TO 26
PRINT #1, C1$ + C2$ + C3$ + MID$(A, I4, 1)
NEXT I4
NEXT I3
NEXT I2
NEXT I1
CLOSE
SYSTEM
Mac
The QBasic Forum
http://www.network54.com/Forum/13959