First test project in Gambas

Post your Gambas programming questions here.
Post Reply
Mudassir
Posts: 13
Joined: Monday 5th February 2024 11:10pm

First test project in Gambas

Post 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
.....
User avatar
BruceSteers
Posts: 1579
Joined: Thursday 23rd July 2020 5:20pm
Location: Isle of Wight
Contact:

Re: First test project in Gambas

Post 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("")

If at first you don't succeed , try doing something differently.
BruceS
User avatar
BruceSteers
Posts: 1579
Joined: Thursday 23rd July 2020 5:20pm
Location: Isle of Wight
Contact:

Re: First test project in Gambas

Post 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"
If at first you don't succeed , try doing something differently.
BruceS
User avatar
cogier
Site Admin
Posts: 1127
Joined: Wednesday 21st September 2016 2:22pm
Location: Guernsey, Channel Islands

Re: First test project in Gambas

Post 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
Post Reply