Why does it want a boxed string?

Post

Posted
Rating:
#1 (In Topic #1565)
Regular
DIYTinkerer is in the usergroup ‘Regular’
Hi,
Not sure what has happened, part of my code which was working is now failing with error
Type mismatch: wanted _BoxedString, got String instead

this is the offending line
  

Code (gambas)

  1.   Dim workingImLoc As String = File.Name(FMain.imageLocation)

the error implies workingImLoc is a boxed String but I've only just declared it (as a string) in the above line and it's not declared as a boxed string

the contents of FMain.imageLocation is a normal String with the following content "/home/simon/Documents/Gambas/Sol_Observer1.7/2025-07-16-0701_6-Capture_Focus_lapl2_ap514_REFPS.jpg"

it is declared in FMain as follows

Code (gambas)

  1. Public imageLocation As String = "" 'this holds the file location of the image

As I said this changed when I was working on a different class (for a save form) which doesn't even get initiated at this point in the program, so not sure what I've done wrong, any ideas or suggestions?
Online now: No Back to the top

Post

Posted
Rating:
#2
Guru
BruceSteers is in the usergroup ‘Guru’
 I assume FMain is not the startup class?

FMain would not be created until it is accessed somehow.
By accessing the FMain variable you then create the form.

The error is probably in FMain somewhere.

I assume a lot as you have not provided an example just some little bits of code.
Online now: No Back to the top

Post

Posted
Rating:
#3
Regular
DIYTinkerer is in the usergroup ‘Regular’
Hi Bruce,
FMain is the start-up class, it is the first form that appears, the project is quite large I can share the whole thing but didn't think it wise give it is reasonably large

FMain starts like this

Code (gambas)

  1. ' Gambas class file
  2.  
  3. Public imageLocation As String = "" 'this holds the file location of the image

imageLocation is populated by FOpen (FOpen is a file open dialogue called from a menu event in FMain) as follows…

Code (gambas)

  1. Public Sub fileChooser_Activate()
  2.  
  3.   If Exist(FileChooser.SelectedPath) Then
  4.    
  5.     FMain.imageLocation = FileChooser.SelectedPath
  6.     FMain.UpdateStatus("gb.CLS")
  7.     FMain.UpdateStatus("IMAGE PATH:" & "<b>" & FMain.imageLocation & "</b>")
  8.    
  9.   Else
  10.     FMain.imageLocation = ""
  11.   Endif
  12.   saveSettings() 'save the selected directory
  13.   closeDown()
  14.  

I select as file using FOpen and FMain.imageLocation is populated with "/home/simon/Documents/Gambas/Sol_Observer1.7/2025-07-16-0701_6-Capture_Focus_lapl2_ap514_REFPS.jpg" (or whatever file I selected) which is what I expected.

after the file is selected FOpen closes and the next relevant step in the process, calls getDatefromFileName() a function to extract some information from the file name, which crashes with the type mismatch error

Code (gambas)

  1. Private Sub getDatefromFileName()
  2.  
  3.   'see if we can get date and time data from filename i.e. a WinJupos compliant filename
  4.   'requires filename starts with the format YYYY-MM-DD-HHmm to retreive date and time from filename
  5.   Dim workingImLoc As String = File.Name(FMain.imageLocation)
  6.  
  7.   Dim sTemp As String
  8.   ' Dim
  9.   If Len(workingImLoc) > 15 Then
  10.     sTemp = Left$(workingImLoc, 4)
  11.     If IsNumber(sTemp) Then
  12.       _Year = Val(sTemp)
  13.     Else
  14.       _Year = -9999
  15.       Return
  16.     Endif
  17.     sTemp = Mid$(workingImLoc, 6, 2)
  18.     If IsNumber(sTemp) Then
  19.       _Month = Val(sTemp)
  20.     Else
  21.       _Year = -9999
  22.       Return
  23.     Endif
  24.     sTemp = Mid$(workingImLoc, 9, 2)
  25.     If IsNumber(sTemp) Then
  26.       _Date = Val(sTemp)
  27.     Else
  28.       _Year = -9999
  29.       Return
  30.     Endif
  31.     sTemp = Mid$(workingImLoc, 12, 2)
  32.     If IsNumber(sTemp) Then
  33.       _Hour = Val(sTemp)
  34.     Else
  35.       _Year = -9999
  36.       Return
  37.     Endif
  38.     sTemp = Mid$(workingImLoc, 14, 2)
  39.     If IsNumber(sTemp) Then
  40.       _Min = Val(sTemp)
  41.     Else
  42.       _Year = -9999
  43.       Return
  44.     Endif
  45.   Else
  46.     _Year = -9999
  47.     Return
  48.  
  49.  

Here is the project.
Attachment
Online now: No Back to the top

Post

Posted
Rating:
#4
Guru
BruceSteers is in the usergroup ‘Guru’
Now we are talking.

So i got the same error and upon investigating i found File.Name was expecting a string as a property, not the method with arguments.

The reason was thus..

In fOrig.form you have a Menu named File

this overrides/breaks the use of File.class causing your use of File.Name to be the same as Menu.Name

You should not use any words as Name for Menus/Controls that are gambas classes or function names
So change the File Menu name to mnuFile or something like that and all will be fixed :)
Online now: No Back to the top

Post

Posted
Rating:
#5
Guru
BruceSteers is in the usergroup ‘Guru’
See why the project or an example is better?

You could have spent days posting snippets of code and we would still never have found the problem.

With an example that produces the problem or the project itself it all becomes clear so much easier :)
Online now: No Back to the top

Post

Posted
Rating:
#6
Regular
DIYTinkerer is in the usergroup ‘Regular’
OK I've learnt three lessons today.
1. Bruce, you are awesome
2. Share the code
3. Did I mention you are awesome :)
Online now: No Back to the top

Post

Posted
Rating:
#7
Guru
BruceSteers is in the usergroup ‘Guru’

DIYTinkerer said

OK I've learnt three lessons today.
1. Bruce, you are awesome
2. Share the code
3. Did I mention you are awesome :)

Haha, to be fair I got that from Benoit.
One of the first things he asks when you report an issue is "please provide a project that reproduces the problem"

It makes sense and has many benefits.
Many times I have found the problem in my own code while making a sample project that for some reason will not reproduce the problem and helps me find where i went wrong.
Online now: No Back to the top
1 guest and 0 members have just viewed this.