|
-
May 19th, 2002, 03:37 PM
#1
Thread Starter
Junior Member
Textfiles
Ok, here's something that's stumping me (a novice), and I wonder if any of you experts can help.
I have a textbox which a user can type into and save the contents, but if they put quotes in:
He said "I don't think so" as he moved forward
VB throws a wobbler when loading the text back in and displays only up to the first lot of quotes:
He said
I'm using Write #1, to save the text. How do I allow for anything to be typed in and for VB to read it back ok?
Thanks in advance.
PHP Code:
On Error GoTo Hell
:¬) MrNick
-
May 19th, 2002, 03:44 PM
#2
-= B u g S l a y e r =-
Sample that seem to work just fine
VB Code:
Private Sub Command1_Click()
'Save the text
Open "C:\TEST.TXT" For Output As #1
Write #1, Text1.Text
Close #1
End Sub
Private Sub Command2_Click()
'Load the text
Open "C:\TEST.TXT" For Input As #1
Text1.Text = Input(LOF(1), 1)
Close #1
End Sub
if u have to use Write, show us how u do it.
-
May 20th, 2002, 03:44 AM
#3
Thread Starter
Junior Member
I have many textboxes and everything is saved as one textfile, this is how i'm using it:
CommonDialog1.InitDir = App.Path 'Initial folder to show
CommonDialog1.Flags = cdlOFNOverwritePrompt
CommonDialog1.Filter = "Review Files (*.rvw)|*.rvw|All Files (*.*)|*.*" 'The file types it recognises
CommonDialog1.DialogTitle = "Plese select the Filename to Save." 'Title
CommonDialog1.ShowSave 'Show file requester
Open CommonDialog1.FileName For Output As #1
Write #1, txtGameTitle.Text
Write #1, txtReviewer.Text
Write #1, txtAuthor.Text
Write #1, cmbGameType.Text
..
..
..
I'm not exactly sure what you mean by: Text1.Text = Input(LOF(1), 1) peet, as i'm almost a complete novice!
PHP Code:
On Error GoTo Hell
:¬) MrNick
-
May 20th, 2002, 04:03 AM
#4
Instead of Write
use
Print
-
May 20th, 2002, 04:14 AM
#5
Thread Starter
Junior Member
Done that mendhak, but there are also commas in the textfile and when loading it back, it throws a wobbler at the first comma .
I need to be able to read and extract lines from a textfile no matter what the text is (commas, quotes, sysmbols, whatever).
any suggestions?
PHP Code:
On Error GoTo Hell
:¬) MrNick
-
May 20th, 2002, 04:25 AM
#6
Junior Member
Hi MrNick
My Text was like this a,b'c@#$%^&*
Private Sub Command1_Click()
'Save the text
Open "C:\TEST.TXT" For Output As #1
Print #1, CStr(Text1.Text)
Close #1
End Sub
Private Sub Command2_Click()
'Load the text
Open "C:\TEST.TXT" For Input As #1
' Text1.Text = Input(LOF(1) - 2, 1)
Do While Not EOF(1) - 1 ' Loop until end of file.
Text1.Text = Text1.Text & Input(1, #1) ' Get one character.
Loop
Close #1
End Sub
This one works fine...
It's nothing but what Peet and Mendhak has suggested u...
-
May 20th, 2002, 04:40 AM
#7
I believe the only problem occurs at double quotes "
-
May 20th, 2002, 04:42 AM
#8
Junior Member
Yes Mendhak u r correct
-
May 20th, 2002, 04:44 AM
#9
Thread Starter
Junior Member
I've no doubt that your solution works Padma and i'm greatful, but I haven't a clue what it means . Especially the Input(LOF(1) - 2, 1)!
It seems that you're reading one char at a time and putting it in a textbox yes?
I have 10 richtextboxes and I wish to place each line in a seperate richtextbox. Here is my entire save routine:
Private Sub mnusave_Click()
CommonDialog1.InitDir = App.Path 'Initial folder to show
CommonDialog1.Flags = cdlOFNOverwritePrompt
CommonDialog1.Filter = "Review Files (*.rvw)|*.rvw|All Files (*.*)|*.*" 'The file types it recognises
CommonDialog1.DialogTitle = "Plese select the Filename to Save." 'Title
CommonDialog1.ShowSave 'Show file requester
Open CommonDialog1.FileName For Output As #1
Write #1, txtGameTitle.Text
Write #1, txtReviewer.Text
Write #1, txtAuthor.Text
Write #1, cmbGameType.Text
Write #1, cmbGenre1.Text
Write #1, cmbGenre2.Text
Write #1, txtOtherGenre.Text
Write #1, hsrInterface.Value
Write #1, txtInterface.Text
Write #1, hsrStory.Value
Write #1, txtStory.Text
Write #1, hsrCommands.Value
Write #1, txtCommands.Text
Write #1, hsrProblems.Value
Write #1, txtProblems.Text
Write #1, hsrLogic.Value
Write #1, txtLogic.Text
Write #1, hsrDescription.Value
Write #1, txtDescription.Text
Write #1, hsrConversation.Value
Write #1, txtConversation.Text
Write #1, hsrWriting.Value
Write #1, txtWriting.Text
Write #1, hsrFeatures.Value
Write #1, txtFeatures.Text
Write #1, hsrBonus.Value
Write #1, txtBonus.Text
Write #1, hsrSupport.Value
Write #1, txtSupport.Text
Write #1, txtPros.Text
Write #1, txtCons.Text
Write #1, lblscore.Caption
Write #1, txtAdvice.Text
errorhandler:
Close #1
End Sub
and the entire LOAD routine:
Private Sub mnuload_Click() 'Load the Review (text file)
Dim Temp As String
CommonDialog1.Filter = "Review Files (*.rvw)|*.rvw|All Files (*.*)|*.*"
CommonDialog1.DialogTitle = "Plese select the Character to open." 'Title
CommonDialog1.ShowOpen 'Show file requester
Open CommonDialog1.FileName For Input As #1 'Use the selected file
Input #1, Temp
txtGameTitle.Text = Temp
Input #1, Temp
txtReviewer.Text = Temp
Input #1, Temp
txtAuthor.Text = Temp
Input #1, Temp
cmbGameType.Text = Temp
Input #1, Temp
cmbGenre1.Text = Temp
Input #1, Temp
If Temp = "(None)" Then Temp = "None"
cmbGenre2.Text = Temp
Input #1, Temp
txtOtherGenre.Text = Temp
'Interface
Input #1, Temp
hsrInterface.Value = Temp
Input #1, Temp
txtInterface.Text = Temp
'The Story
Input #1, Temp
hsrStory.Value = Temp
Input #1, Temp
txtStory.Text = Temp
'Commands
Input #1, Temp
hsrCommands.Value = Temp
Input #1, Temp
txtCommands.Text = Temp
'Problems
Input #1, Temp
hsrProblems.Value = Temp
Input #1, Temp
txtProblems.Text = Temp
'The Logic
Input #1, Temp
hsrLogic.Value = Temp
Input #1, Temp
txtLogic.Text = Temp
'RoomDescriptions
Input #1, Temp
hsrDescription.Value = Temp
Input #1, Temp
txtDescription.Text = Temp
'Conversation
Input #1, Temp
hsrConversation.Value = Temp
Input #1, Temp
txtConversation.Text = Temp
'Writing Style
Input #1, Temp
hsrWriting.Value = Temp
Input #1, Temp
txtWriting.Text = Temp
'Extra Features
Input #1, Temp
hsrFeatures.Value = Temp
Input #1, Temp
txtFeatures.Text = Temp
'Bonus Points
Input #1, Temp
hsrBonus.Value = Temp
lblBonus.Caption = Temp
Input #1, Temp
txtBonus.Text = Temp
Input #1, Temp
hsrSupport.Value = Temp
Input #1, Temp
txtSupport.Text = Temp
Input #1, Temp
txtPros.Text = Temp
Input #1, Temp
txtCons.Text = Temp
Input #1, Temp
lblscore.Caption = Temp
Input #1, Temp
txtAdvice.Text = Temp
Close #1
End Sub
and here's the actual textfile:
House of the Damned
davidw
Sam McCall
Finished
Fantasy
None
5
Fairly standard font (Arial, 12) with no fancy use of bold or italics to heighten the effect.
7
Fairly interesting idea. Your car breaks down and you end up running through the woods to a haunted house (the House of the Damned of the title) being chased by wolves. Nothing else is known which is a shame because it would have been nice to know a little more about what you are expected to do in the house after your arrival.
5
A mixed bunch. Some of the commands were fairly straightforward and logical, others took quite a bit of figuring out (and some I only discovered after looking in the generator). "Use ladder with window" was a confusing one that took some guess-the-verbing and would have been a lot less hassle as "use ladder"' or maybe allowing the player to drop the ladder and then 'climb' it.
10
5
For the most part the puzzles were reasonably logical to figure out but there were a few ("'mix fish with whiskey", "hit tile with hammer" and particularly "use ladder with window") that could have been handled better.
7
Above average for the most part - the graveyard was genuinely creepy and there were more than a few locations in the house itself which were well written, although there were also a few that felt a bit flat. But then, how many interesting ways can there be to describe a simple room?
6
Only four - two can't be questioned but the other two have quite interesting things to say (if you can figure out what to ask them!)
7
Well written for the most part although some of the locations were perhaps a little basic. The graveyard was atmospherically done (the eerie crow being a nice touch). There was also good use of events to indicate the wind howling, a grandfather clock chiming, etc. Character dialogue was interesting without ever really becoming a must-have.
5
No advanced features that I could see but the game plays fairly well without and so this isn't a hindrance in any way.
7
No hints or walkthrough available but a character who can answer quite a lot of questions makes the game more interesting. Also some quite amusing tasks ('kiss eggbert' and 'drink from toilet') added a little comic element to the proceedings.
5
No real instructions or background info (you have no idea who the character is or why he/she is running through the woods at the start of the adventure following their car breaking down). That said, the introduction was well written and the lack of instructions or background isn't a problem that affects playing the game.
Well written, atmospheric, and more than interesting enough to keep you playing again and again until you finish it.
Nothing really bad to say about it but the guess-the-verb usage was a little frustrating at times.
65
You've created a decient game but it could be improved a lot.
Could you explain a bit simpler for us VB thickies
PHP Code:
On Error GoTo Hell
:¬) MrNick
-
May 20th, 2002, 04:44 AM
#10
no Padma, YOU are correct, because I just tested yours and uhm... everything works.
even commas.
Can you try this: asf","dfksl';,as;"
-
May 20th, 2002, 04:59 AM
#11
Junior Member
Hi Mendhak,
Try this by filling text as """" and try to retrieve ...
-
May 20th, 2002, 07:13 AM
#12
Thread Starter
Junior Member
Can anyone help with a simpler solution (I'm only a newbie!)
Pretty Please
PHP Code:
On Error GoTo Hell
:¬) MrNick
-
May 20th, 2002, 07:24 AM
#13
Thread Starter
Junior Member
Oops! Made a bit of an error in one of my postings here, they are not richtext boxes, just normal textboxes.
PHP Code:
On Error GoTo Hell
:¬) MrNick
-
May 20th, 2002, 03:26 PM
#14
Thread Starter
Junior Member
Can anyone help with a simpler solution (I'm only a newbie!)
Pretty Please?
PHP Code:
On Error GoTo Hell
:¬) MrNick
-
May 20th, 2002, 03:46 PM
#15
-= B u g S l a y e r =-
Mr Nick, this is a way to save and load all textboxes and checkboxes using an ini file
VB Code:
Option Explicit
Private Declare Function GetPrivateProfileString _
Lib "kernel32" Alias "GetPrivateProfileStringA" (ByVal _
lpApplicationName As String, ByVal lpKeyName As String, _
ByVal lpDefault As String, ByVal lpReturnedString As _
String, ByVal nSize As Long, ByVal lpFileName As String) As _
Long
Private Declare Function WritePrivateProfileString _
Lib "kernel32" Alias "WritePrivateProfileStringA" (ByVal _
lpApplicationName As String, ByVal lpKeyName As Any, ByVal _
lpString As Any, ByVal lpFileName As String) As Long
Private Function ReadINI(strsection As String, strkey As String, strfullpath As String) As String
Dim strbuffer As String
Let strbuffer$ = String$(750, Chr$(0&))
Let ReadINI$ = Left$(strbuffer$, GetPrivateProfileString(strsection$, ByVal LCase$(strkey$), "", strbuffer, Len(strbuffer), strfullpath$))
End Function
Private Sub WriteINI(strsection As String, strkey As String, strkeyvalue As String, strfullpath As String)
Call WritePrivateProfileString(strsection$, UCase$(strkey$), strkeyvalue$, strfullpath$)
End Sub
Private Sub cmdLoad_Click()
Dim sFileName As String
Dim c As Control
'Load data from Ini File
sFileName = App.Path & "\" & Me.Name & ".INI"
For Each c In Me
If TypeOf c Is TextBox Then c.Text = ReadINI("DATA_TextBox", c.Name, sFileName)
If TypeOf c Is CheckBox Then c.Value = Val(ReadINI("DATA_CheckBox", c.Name, sFileName))
Next c
End Sub
Private Sub cmdSave_Click()
Dim sFileName As String
Dim c As Control
'Save data to ini file
sFileName = App.Path & "\" & Me.Name & ".INI"
For Each c In Me
If TypeOf c Is TextBox Then WriteINI "DATA_TextBox", c.Name, c.Text, sFileName
If TypeOf c Is CheckBox Then WriteINI "DATA_CheckBox", c.Name, c.Value, sFileName
Next c
End Sub
I made this for someone else on this forum, (don't remember who )
Anyway, this is easy to expand in order to cover other controls aswell..
Mendhak : WHAT THE H*** happened to u'r avatar ??? ... cool
-
May 20th, 2002, 03:49 PM
#16
VB throws a wobbler when loading the text
what kind of thing "throws a wobbler"?
-
May 21st, 2002, 05:48 PM
#17
Thread Starter
Junior Member
Thanks to all who've helped I've now solved the problem quite simply; instead of reading the textfile with Input #1,<whatever>, i used Line Input #1,<whatever>.
Thanks again.
PHP Code:
On Error GoTo Hell
:¬) MrNick
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|