Saving/reading checkbox states in prefs causes type mismatch 
Author Message
 Saving/reading checkbox states in prefs causes type mismatch

Greetings to all.
Third question in as many days...sigh.
Really enjoying my RB though! Matt's book is a godsend; the RB manuals leave
a little to be desired though. <g>
(Again, I would like to solicit advice for the best RB sites for code
examples...)

Anyway, I'm saving my Prefs, and one section is a group of checkboxes.
When I retrieve my prefs, in the main windows activate section, I get 'type
mismatch' on the line indicated below.

I'm certain this is something simple, but for the life of me I can't peg
it...anyone have any idea of what I'm missing here?

Code follows, and thanks in advance.
Scott

--------------
//saving prefs method

  Dim folder,file As FolderItem
  Dim p As String
  Dim fileWriteTo As TextOutputStream

  'winmain.txttop.text = winmain.top
  'winmain.txtleft.text = winmain.left

  folder=PreferencesFolder
  p=folder.AbsolutePath+"GoggleX Prefs"
  file=GetFolderItem(p)

  fileWriteTo=file.CreateTextFile

  fileWriteTo.writeLine winmain.txtterm.text
  'fileWriteTo.writeLine winmain.mnu1.ListIndex

  //load the checkbox states...
  fileWriteTo.writeLine winprefs.chk1.value
  fileWriteTo.writeLine winprefs.chk2.value
  fileWriteTo.writeLine winprefs.chk3n.value
  fileWriteTo.writeLine winprefs.chk4.value

  //load the other options...
  fileWriteTo.writeLine winprefs.chkSavePos.value
  fileWriteTo.writeLine winprefs.chkstartup.value
  fileWriteTo.writeLine winprefs.chkTypeahead.value

  //yoink. write the prefs file.
  fileWriteTo.Close

====================================================

////////////load prefs method

  Dim folder,file As FolderItem
  Dim p As String
  Dim fileReadFrom As TextInputStream

  folder=PreferencesFolder
  p=folder.AbsolutePath+"GoggleX Prefs"
  file=GetFolderItem(p)

  if file.exists then
    fileReadFrom=file.OpenAsTextFile
    'winmain.txttop.text = fileReadFrom.ReadLine
    'winmain.txtleft.text = fileReadFrom.ReadLine

    winmain.txtterm.text = filereadFrom.readline

//load the checkbox states...
      winprefs.chk1.value = filereadFrom.readline  // here's where the type
// mismatch starts; if I comment this out, it simply goes to the next line
// with the same error

      winprefs.chk2.value = filereadFrom.readline
      winprefs.chk3.value = filereadFrom.readline
      winprefs.chk4.value = filereadFrom.readline

    //load the other options...
      winprefs.chkSavePos.value = filereadFrom.readline
      winprefs.chkstartup.value = filereadFrom.readline
      winprefs.chkTypeahead.value = filereadFrom.readline

    fileReadFrom.Close
  end if



Wed, 08 Sep 2004 11:53:30 GMT  
 Saving/reading checkbox states in prefs causes type mismatch
One more thing; as you can see below, I was also looking to save and restore
my window positions. What's wrong there?

AND, in the 'save prefs' method, I seem to have added an 'n' to chk3.value.
Ignore that, tis a typo.
:-)

Thanks.
Scott


Quote:

> Greetings to all.
> Third question in as many days...sigh.
> Really enjoying my RB though! Matt's book is a godsend; the RB manuals leave
> a little to be desired though. <g>
> (Again, I would like to solicit advice for the best RB sites for code
> examples...)

> Anyway, I'm saving my Prefs, and one section is a group of checkboxes.
> When I retrieve my prefs, in the main windows activate section, I get 'type
> mismatch' on the line indicated below.

> I'm certain this is something simple, but for the life of me I can't peg
> it...anyone have any idea of what I'm missing here?

> Code follows, and thanks in advance.
> Scott

> --------------
> //saving prefs method

> Dim folder,file As FolderItem
> Dim p As String
> Dim fileWriteTo As TextOutputStream

> 'winmain.txttop.text = winmain.top
> 'winmain.txtleft.text = winmain.left

> folder=PreferencesFolder
> p=folder.AbsolutePath+"GoggleX Prefs"
> file=GetFolderItem(p)

> fileWriteTo=file.CreateTextFile

> fileWriteTo.writeLine winmain.txtterm.text
> 'fileWriteTo.writeLine winmain.mnu1.ListIndex

> //load the checkbox states...
> fileWriteTo.writeLine winprefs.chk1.value
> fileWriteTo.writeLine winprefs.chk2.value
> fileWriteTo.writeLine winprefs.chk3n.value
> fileWriteTo.writeLine winprefs.chk4.value

> //load the other options...
> fileWriteTo.writeLine winprefs.chkSavePos.value
> fileWriteTo.writeLine winprefs.chkstartup.value
> fileWriteTo.writeLine winprefs.chkTypeahead.value

> //yoink. write the prefs file.
> fileWriteTo.Close

> ====================================================

> ////////////load prefs method

> Dim folder,file As FolderItem
> Dim p As String
> Dim fileReadFrom As TextInputStream

> folder=PreferencesFolder
> p=folder.AbsolutePath+"GoggleX Prefs"
> file=GetFolderItem(p)

> if file.exists then
>   fileReadFrom=file.OpenAsTextFile
>   'winmain.txttop.text = fileReadFrom.ReadLine
>   'winmain.txtleft.text = fileReadFrom.ReadLine

>   winmain.txtterm.text = filereadFrom.readline

> //load the checkbox states...
>     winprefs.chk1.value = filereadFrom.readline  // here's where the type
> // mismatch starts; if I comment this out, it simply goes to the next line
> // with the same error

>     winprefs.chk2.value = filereadFrom.readline
>     winprefs.chk3.value = filereadFrom.readline
>     winprefs.chk4.value = filereadFrom.readline

>   //load the other options...
>     winprefs.chkSavePos.value = filereadFrom.readline
>     winprefs.chkstartup.value = filereadFrom.readline
>     winprefs.chkTypeahead.value = filereadFrom.readline

>   fileReadFrom.Close
> end if



Wed, 08 Sep 2004 11:59:31 GMT  
 Saving/reading checkbox states in prefs causes type mismatch


Quote:
>  //load the checkbox states...
>  fileWriteTo.writeLine winprefs.chk1.value
>  fileWriteTo.writeLine winprefs.chk2.value
>  fileWriteTo.writeLine winprefs.chk3n.value
>  fileWriteTo.writeLine winprefs.chk4.value

Despite the fact that it's a boolean value your writing to disk, your
using the WriteLine, which saves it as a string in this case,
basically...

Quote:
>      winprefs.chk1.value = filereadFrom.readline  // here's where the type
>// mismatch starts; if I comment this out, it simply goes to the next line
>// with the same error

  And here, you read it in with ReadLine (which returns a string....)
You'd need to do one of two things (I'd have to look at the pref's
file with a text editor and see how it stores the data to be certain,
but its either:

Dim A as Integer;
Dim B as String;

        B = FileReadFrom.readline
        A = Val(B)
        winprefs.chk1.value = A

or

           B = FileReadFromReadLine
           if (b = "True") Then
                 winprefs.chk1.value = true
           else
                 winprefs.chk1.value = false
           end if

(untested, but something like that's what your looking for....) If you
see a 0 , 1, or -1 in the pref's file you wrote, use the first method,
if you see True or False, use the second....



Wed, 08 Sep 2004 22:46:48 GMT  
 Saving/reading checkbox states in prefs causes type mismatch


Quote:
>One more thing; as you can see below, I was also looking to save and restore
>my window positions. What's wrong there?

>AND, in the 'save prefs' method, I seem to have added an 'n' to chk3.value.
>Ignore that, tis a typo.

Same thing as the check boxes, your reading in a
string into a numeric field.... Convert it to numeric first using
val() ....


Wed, 08 Sep 2004 22:47:48 GMT  
 Saving/reading checkbox states in prefs causes type mismatch
Thanks John. I'm working at it now; makes perfect sense now.
:-)

Scott



Quote:


>>  //load the checkbox states...
>>  fileWriteTo.writeLine winprefs.chk1.value
>>  fileWriteTo.writeLine winprefs.chk2.value
>>  fileWriteTo.writeLine winprefs.chk3n.value
>>  fileWriteTo.writeLine winprefs.chk4.value
> Despite the fact that it's a boolean value your writing to disk, your
> using the WriteLine, which saves it as a string in this case,
> basically...

>>      winprefs.chk1.value = filereadFrom.readline  // here's where the type
>> // mismatch starts; if I comment this out, it simply goes to the next line
>> // with the same error
> And here, you read it in with ReadLine (which returns a string....)
> You'd need to do one of two things (I'd have to look at the pref's
> file with a text editor and see how it stores the data to be certain,
> but its either:

> Dim A as Integer;
> Dim B as String;

>       B = FileReadFrom.readline
>       A = Val(B)
>       winprefs.chk1.value = A

> or

>          B = FileReadFromReadLine
>          if (b = "True") Then
>                winprefs.chk1.value = true
>          else
>                winprefs.chk1.value = false
>          end if

> (untested, but something like that's what your looking for....) If you
> see a 0 , 1, or -1 in the pref's file you wrote, use the first method,
> if you see True or False, use the second....



Wed, 08 Sep 2004 23:54:51 GMT  
 Saving/reading checkbox states in prefs causes type mismatch

Quote:

>   folder=PreferencesFolder
>   p=folder.AbsolutePath+"GoggleX Prefs"
>   file=GetFolderItem(p)

Argh.

file= PreferencesFolder.child("GoggleX Prefs")

That's the correct way!

Quote:

>   fileWriteTo=file.CreateTextFile

check for nil!?

Quote:
>   fileWriteTo.writeLine winmain.txtterm.text

an editfield may contain mulitple lines so this might be logical wrong.

Quote:
>   //load the checkbox states...
>   fileWriteTo.writeLine winprefs.chk1.value
>   fileWriteTo.writeLine winprefs.chk2.value
>   fileWriteTo.writeLine winprefs.chk3n.value
>   fileWriteTo.writeLine winprefs.chk4.value

boolean is not string.

Quote:
>   if file.exists then

if file<>Nil and file.exists then

is better.

Quote:
>     fileReadFrom=file.OpenAsTextFile

if fileReadFrom <>nil then

Quote:
>     winmain.txtterm.text = filereadFrom.readline

Will only read one line. Maybe ok, maybe not.

Quote:
> //load the checkbox states...
>       winprefs.chk1.value = filereadFrom.readline  // here's where the type
> // mismatch starts; if I comment this out, it simply goes to the next line
> // with the same error

Why? because string is not boolean.

Mfg
Christian

--
I'm looking for a rich woman, I pay anything

http://www.christians-software.de (Free Mac/Win software)



Thu, 09 Sep 2004 05:15:58 GMT  
 
 [ 6 post ] 

 Relevant Pages 

1. save prefs( colors )

2. type mismatches/access type

3. Restoring the state of a checkbox

4. checkbox on/off state

5. Saving a file -> Save as type

6. rexx saving checkbox

7. ActiveX Type mismatch...

8. ole automation error parameter 1 type mismatch

9. type mismatch, S87

10. Data type mismatch ?

11. newby with a simple Type mismatch problem.

12. External Subroutine type mismatch

 

 
Powered by phpBB® Forum Software