Page 1 of 1

First test project in Gambas

Posted: Friday 8th March 2024 12:50pm
by Mudassir
Hi,
I am trying to do my first test project in Gambas after maybe 12 years not looking at VB.. This would a basic checker tool to assist me writing titles & keywords for my amazon listings and to calculate fee and taxes etc. I am facing some problems or maybe I don't understand to work with it yet. Some help would be appreciated to guide me solve the riddles:

When I close the application / form it clears the text from clipboard (in case I copy something from TextBox).. how can I fix it?

And below code to validate a product title is reading hyphen (-) as invalid character from TextBox input (typed or pasted).. though the character '-' is included in the pattern.. idk why?
.....
  For i = 1 To Len(TextBox2.Text)
    If Mid(TextBox2.text, i, 1) Not Like "[A-Z, a-z, 0-9, ',', '.', '-', ' ', '/']" Then
      ErrorString = ErrorString & Mid(TextBox2.Text, i, 1)
      PatMatch = False
    Endif
  Next
  
  If PatMatch = False Then
    TextBox1.Text = Trim(ErrorString)
    TextBox1.Foreground = Color.DarkRed
  Else 
    TextBox1.Text = "None"
    TextBox1.Foreground = Color.DarkGreen
  Endif
.....

Re: First test project in Gambas

Posted: Friday 8th March 2024 5:25pm
by BruceSteers
install diodon or clipman or some other clipboard manager.

A clipboard contents is held active by each program task, if you close the task the clipboard contents die with it.

This is true for EVERY program you use on linux.

the only way around it is to have a clipboard manager like diodon tool installed.

And there's easier ways to remove/detect valid characters


ErrorString = Split(TextBox2.Text, ",.-, /", Null, True).Join("")


Re: First test project in Gambas

Posted: Saturday 9th March 2024 12:10am
by BruceSteers
Also read Like info harder...
https://gambaswiki.org/wiki/lang/like

maybe you want this...

Like "{A-Z, a-z, 0-9, ',', '.', '-', ' ', '/'}"


I do not know
I do not use Like in detail like that but documentations says...
{aaa,bbb,...} One of the strings between the square brackets. The strings are separated by commas.

and that not accurate as it should say "curly brackets" not "square brackets"

Re: First test project in Gambas

Posted: Saturday 9th March 2024 2:47pm
by cogier
I'm not an expert with Like either, but I think this will do what you want.

Public Sub Button1_Click()

  Dim i As Integer
  Dim ErrorString As String
  Dim PatMatch As Boolean = True

  For i = 1 To Len(TextBox2.Text)
    If InStr("abcdefghijklmnopqrstuvwxyz0123456789,.- /", LCase(Mid(TextBox2.text, i, 1))) <> 0 Then
      ErrorString = ErrorString & Mid(TextBox2.Text, i, 1)
      PatMatch = False
    Endif
  Next

  If PatMatch = False Then
    TextBox2.Text = Trim(ErrorString)
    TextBox2.Foreground = Color.DarkRed
  Else
    TextBox2.Text = "None"
    TextBox2.Foreground = Color.DarkGreen
  Endif

End