• Welcome to PlanetSquires Forums.
 

find and replace

Started by raymw, September 28, 2019, 09:25:04 AM

Previous topic - Next topic

Paul Squires

Quote from: raymw on October 05, 2019, 01:29:54 PM
... I've created a couple of hidden listboxes in the graphics form, and push the values from my main form to there. It works OK, but I may work on it some more.
That seems like a lot of hassle when you could simply have a global variable referencing a TYPE structure that contains all of the data you need.

TYPE MyGlobalType
   MyString As String
   MyLong As Long
   MySingle As Single
   ' etc...
END TYPE

DIM SHARED gMyType AS MyGlobalType
Paul Squires
PlanetSquires Software
WinFBE Editor and Visual Designer

Paul Squires

Quote from: Paul Squires on October 04, 2019, 06:33:52 AM
Quote from: raymw on October 03, 2019, 09:04:54 PM
Right, almost there, but I'm finding that often the border styles for the forms or list boxes appear to randomly change to a non-valid type for that particular control. I reset it in the designer properties, it then compiles, until the next time, it is happening rather frequently.
Interesting that you'd say that because eary in the visual designer development I would notice this as well. I implemented a fix and it seemed to had worked, but if you're seeing it then I better investigate more. It is related to a got/lost focus issue when the user moves from control to control.

I did notice (and fixed) the situation where you have a dropdown combobox open for a particular control property but then switch to another control and that dropdown remains open for the newly selected control's property. This "may" be related to the problem that we're seeing. You'll be able to test it when I release the next version.
Paul Squires
PlanetSquires Software
WinFBE Editor and Visual Designer

SeaVipe

Ray, are the 2 forms to do with a CNC machine? Is there operator interaction with the 2 forms? It seems to me that a few shared variables or, as Paul suggests, a global type, would be a much simpler approach. (Unless the forms are required for other things.)
Clive Richey

raymw

#33
Hi Clive,

Not much operator interaction, mainly change a tool size,  centre the workpiece. I want to keep the graphics form as a separate inc file, I will modify it to read in the gcode directly, useful for quick checks. It just generates code for machining objects. No real purpose, maybe jelly moulds? just sort of interesting. Instead of using cad, it is easier to enter a few values. The only operator is me, and possibly one or two other interested folk. I started programmatically generating  Gcode back in dos days, (using visual basic for dos - Microsoft denied producing it when I queried if it was still around). Converted the spaghetti to c#, adding to it, machining flanges, drill holes on grid patterns, etc. added in code for 3d printing, then a few years ago, I thought, as a separate item, spirals could be interesting, so wrote a c# program to draw spirals, and engrave spirals. A few weeks ago, I was chatting to a friend who does woodturning, I said I could most likely cnc mill bowl shapes, shapes he could not cut on a normal wood turning lathe, and I revisited the spiral program, took the g-code output, parsed it using winfbe added in the third axis, and wrote the 3d code. But, since the milling cutters have a short cutting length, and no reduced shank, it means that on my machine, each cut depth can not be much more than 10mm for a 6mm router. So, every so often, as the cut goes down, it has to plane off the rest of the surface, That was easier to do by porting the c# code to fb, and adding in the planing code. fwiw, the first attempt, without the planing, the shank of the cutter, rotating at 24000rpm, set fire to the resin swarf. Not serious, but smelled a bit.

I find I only get one chance of doing the graphics. If I close the graphics form, and change some values in the main form, and try to draw it again, it opens the graphics form, but draws nothing. I can restart the application, and it will draw whatever I want, but only once.

Just for the sake of it, I may attempt to port my far more complex c# software to freebasic.  Search and replace is quite powerful.

Hi Paul,
I didn't know about global types in free basic. I could most likely more directly translated the c# code, if I'd known. Anyway, if you maintain the winfbx help file, then I think there's a typo in the
AddEllipse (CGpGraphicsPath)  parameter list  along the lines of yyur,yyub,icuryy4me   :D

José Roca

The error is that this line must be removed.

y The width of the bounding rectangle for the ellipse.

Thanks for reporting it.

SeaVipe

Hi Ray, I use global types a lot (my programs tend to be data-intensive). For me, accessing old data files created with VB, UDTs are invaluable. You can do so much with them.

Each time I create a UDT I try to learn a bit more. Here is my most recent attempt (hardly touching the surface):



Type xmlSMS


    Declare Sub get_xml()
    Declare Sub get_sms_count( ByVal in_str as String )
    Declare Sub set_ab( _
                        ByVal in_str as String, _
                        ByVal s_search1 as String, _
                        ByVal s_search2 as String, _
                        ByRef a as Integer, _
                        ByRef b as Integer _
                       )   

Declare Function get_readable_date( ByVal in_str as String ) as String
Declare Function get_contact_name ( ByVal in_str as String ) as String
Declare Function get_number       ( ByVal in_str as String ) as String
        Declare Function get_body         ( ByVal in_str as String ) as String
        Declare Function get_SMS_type     ( ByVal in_str as String ) as String

        readable_date( Any )    as String
contact_name ( Any )    as String
        call_number  ( Any )    as String
        body         ( Any )    as String
SMS_type     ( Any )    as String

file_name               as String = ""
        SMS_count            as Integer = 0
MMS_count As Integer = 0

End Type


Within the body of the include file are routines such as this that match the Declares above:



Sub xmlSMS.get_xml()   


On Local Error Goto xmlError


    Dim As Integer iCounter = 0 
    Dim As Long     f        = Freefile
    Dim As Long o = Open( file_name For Binary Access Read As #f )
    Dim As Integer i = 0
Dim As Integer  x = 0

    If o = 0 Then


        Dim As String s = ""
           
        ? "SMS Good Open"

        Do Until Eof( f )               
           
If Eof( f ) Then Exit Do

            DoEvents()
           
            Line Input #f, s               '' read a line of text ...

If Instr( 1, s, "mms date" ) > 0 Then


i = 0
'' Inceriment count
MMS_count += 1

ElseIf Instr( 1, s, "sms protocol" ) > 0 Then

i = 2
'' Increment count
SMS_count += 1

End If
           
If i = 1 Then

iCounter += 1
ReDim Preserve readable_date( iCounter )
ReDim Preserve contact_name ( iCounter )
ReDim Preserve call_number  ( iCounter )
ReDim Preserve body         ( iCounter )
ReDim Preserve SMS_type     ( iCounter )

readable_date   ( iCounter ) = get_readable_date( s )
                contact_name    ( iCounter ) = get_contact_name( s )


End If

            If i = 2 Then


iCounter += 1
ReDim Preserve readable_date( iCounter )
ReDim Preserve contact_name ( iCounter )
ReDim Preserve call_number  ( iCounter )
ReDim Preserve body         ( iCounter )
ReDim Preserve SMS_type     ( iCounter )
               
call_number     ( iCounter ) = get_number( s )
                body            ( iCounter ) = get_body( s )
                SMS_type ( iCounter ) = get_SMS_type( s )
readable_date   ( iCounter ) = get_readable_date( s )
                contact_name    ( iCounter ) = get_contact_name( s )


            End If
         
        Loop
       
        Close #f

? "SMS_Count = "; SMS_count

    Else
       
        ? "SMS Open Error: " , Err
       
    End If

Exit Sub

xmlError:


? Error code here...

End Sub


It works perfectly so "if it ain't broke, don't fix it"
Sometimes I almost feel like I know what I'm doing!
Clive Richey

raymw

Thanks Clive.
Although i was not going to bother with printing or saving the graphics, the c# code was fairly straightforward
    ' save drawing
'          '  if (myBitmap == null) MessageBox.Show("empty bitmap")
             
'                try
'                 if (myBitmap != null)  then
                   
'                        myBitmap.Save("s:\\test2.png")
'                        myBitmap.Save("s:\\test.jpg", System.Drawing.Imaging.ImageForrmat.Jpeg)
'                        buttonSave.Text = "Saved file."
'                    end if
                 
'                catch (Exception)
                 
'                    MessageBox.Show("There was a problem saving the file." +
'                        "Check the file permissions.")


and

private void button2_Click(object sender, EventArgs e)
       
'            PrintDialog printDialog1 = new PrintDialog()
'            'if (printDialog1.ShowDialog() == printDialog1.
'            '  { printDialog1.   PrintVisual(_PrintCanvas, "My Canvas")  }
'            printDialog1.ShowDialog()
'            if (printDialog1.ShowDialog() == DialogResult.OK)
'            {
'                ' myBitmapb.ToString().Print()
'            }


and looking through the winfbx help, it looks like if I use CMemBmp Class that there is save and print in there. I wonder how many lines of code that will take to get it working. Let's see. Who knows, i may even attempt 3d rendering... I wonder if I could graphically create anaglyphs?

raymw

I'm struggling a bit, confused with other graphic systems I may have used in the past, and not understanding how it fits together in fb. I would like to be able to resize the drawing area on the fly. Dragging the form borders, I could resize the graphics area before drawing to it, but only before the graphic area was created. The other problem, is that it is relatively straightforward to plot lines from a previously constructed list of coordinates, but I'm not sure if I can use path.addline as in the gdiplus examples, and to be able to add lines one by one, as they are generated on another form, so I need to be able to call the graphic area and drawing routines from other forms, and iirc, some of the parameters I tried to share did not seem to be shareable. The winfbx library help is quite good, with examples of the various components, but I believe I need a more comprehensive overview, that explains to me just the fundamental structure, that I do not understand...
I thought I would return to the more inbuilt fb graphics, but  that is not capable of producing the sort of effect I want, unless I go down to the pixel level- no brushes, unless I build them.
At this rate, I'll have to go back to gardening..

raymw

#38
Quote from: Paul Squires on October 05, 2019, 03:38:07 PM
Quote from: Paul Squires on October 04, 2019, 06:33:52 AM
Quote from: raymw on October 03, 2019, 09:04:54 PM
Right, almost there, but I'm finding that often the border styles for the forms or list boxes appear to randomly change to a non-valid type for that particular control. I reset it in the designer properties, it then compiles, until the next time, it is happening rather frequently.
Interesting that you'd say that because eary in the visual designer development I would notice this as well. I implemented a fix and it seemed to had worked, but if you're seeing it then I better investigate more. It is related to a got/lost focus issue when the user moves from control to control.

I did notice (and fixed) the situation where you have a dropdown combobox open for a particular control property but then switch to another control and that dropdown remains open for the newly selected control's property. This "may" be related to the problem that we're seeing. You'll be able to test it when I release the next version.

Hi Paul, another manifestation of the border problem - If I create forms, it seems that any border style I select, does not compile - error is saying ' error 99: No matching overloaded function,ACCCEPTBUTTON()  and similar for CANCELBUTTON()  Loading in a basic program that ran yesterday,  the exe. ran fine, but looking in designer view of form, it shows no entry (blank) in border style in properties. The menu items appear when I click there, as normal, but any selection, it does not compile. This means that I can not reliably edit any programs. I don't know if that helps you in narrowing down the problem area

edit to add here's a couple of parts of what is generated for two different forms, but similar in simplicity - just a form with a button, maybe a couple of text boxes.

function firstType.FormInitializeComponent( byval pForm as firstType ptr ) as LRESULT
   dim as long nClientOffset

   pForm->Text = "Form1"
   pForm->SetBounds(10,10,500,300)
   pForm->OnLoad = @first_Load
   pForm->OnClick = @first_Click
   pForm->Button1.Parent = pForm
   pForm->Button1.Text = "Button1"
   pForm->Button1.SetBounds(126,53-nClientOffset,76,29)
   pForm->Button1.OnClick = @first_Button1_Click
   pForm->Text1.Parent = pForm
   pForm->Text1.Text = "Text1"



function masterformType.FormInitializeComponent( byval pForm as masterformType ptr ) as LRESULT
   dim as long nClientOffset

   pForm->Text = "master form"
   pForm->BorderStyle = FormBorderStyle.FixedSingle
   pForm->AcceptButton = @pForm->y
   pForm->CancelButton = @pForm->y
   pForm->SetBounds(10,10,500,300)
   pForm->Button1.Parent = pForm
   pForm->Button1.Text = "Button1"
   pForm->Button1.SetBounds(146,45-nClientOffset,116,34)
   pForm->Button1.OnClick = @masterform_Button1_Click
   pForm->x.Parent = pForm
   pForm->x.Text = "x"

raymw

Not a problem, but I needed to know, after some poking around, I found that when a form is loaded, it does a resize and a move. If when it loads, it has a form.visible=false, then it does a resize only.