Liberty BASIC Community Forum
« remote button clic »

Welcome Guest. Please Login or Register.
Nov 24th, 2017, 10:50am


Rules|Home|Help|Search|Recent Posts|Notification


« Previous Topic | Next Topic »
Pages: 1  Notify Send Topic Print
 thread  Author  Topic: remote button clic  (Read 288 times)
ombre
New Member
Image


member is offline

Avatar




PM

Gender: Male
Posts: 29
xx remote button clic
« Thread started on: Jul 20th, 2017, 09:40am »

How to clic a button remotely (by program)?
User IP Logged

Rod
Global Moderator
ImageImageImageImageImage


member is offline

Avatar

Graphics = goosebumps!


PM

Gender: Male
Posts: 5567
xx Re: remote button clic
« Reply #1 on: Jul 21st, 2017, 05:22am »

Have a browse at this then Give us more info on what you are trying to do, what is the application you are trying to control, does the button have a hotkey etc etc,
User IP Logged

ombre
New Member
Image


member is offline

Avatar




PM

Gender: Male
Posts: 29
xx Re: remote button clic
« Reply #2 on: Jul 21st, 2017, 10:21am »

First of all this program has no other use than to learn Liberty Basic in general and Random Access Files in particular.
The program works fine except I find the user has to intervene to much in the process of «adding a new entry».
All entries have a specific id number that I want to keep even when I delete an entry. All entries are sorted by name in the listbox. When I delete an entry, the name deleted is replaced by an « * ». When I want to add a new entry, the program first checks if there is an « * » in the list. If so, the new entry will be attributed the id number of the deleted item. If there is no « * », the program attributes an id number that is one more than the total of all the items in the list.
The part I want to tweek is the case of « ButAjout ». For now the program tells the user that there is a free space « * » in the list and asks him to use the case of « ButModif » to add the new entry. What I would like to do is to render the process self-acting : in other words, make the program self-aware and act on it by redirecting it to the « ButModif » button.
Thanks for the help!

Code:
global maxItems
global totalRecords
global num$
dim items$(1),search$(1)

call sOpenDB
call sReadDB
call sCloseDB

nomainwin
WindowWidth = 440
WindowHeight = 240
UpperLeftX=int((DisplayWidth-WindowWidth)/2)
UpperLeftY=int((DisplayHeight-WindowHeight)/2)

listbox #main.ListItem, items$(), sDisplayItem,    5,   5, 175, 185
statictext #main.StatNumero,  "# de l'item:", 190,   7,  80,  25
statictext #main.StatAffNum, "",   260,   7,  95,  25
statictext #main.StatNom,    "Nom:",  190,  32,  80,  25
statictext #main.StatAffNom,   "",   260,  32,  150,  25
statictext #main.StatPrix,   "Prix:",  190,  57,  80,  25
statictext #main.StatAffPrix,  "",  260 ,  57,  95,  25
button #main.ButAjout,   "Ajouter",   sCheckButton, UL, 190, 112,  63,  25
button #main.ButModif,  "Modifier",  sCheckButton, UL, 270, 112,  63,  25
button #main.ButEfface,"Effacer",sCheckButton, UL, 350, 112,  63,  25
'button #main.ButRecherche,"Rechercher", [search],    UL, 190, 162,  80,  25
button #main.ButExit,  "EXIT", [QuitMain], UL, 350, 162,  39,  25

open "Base de données simple" for window as #main
#main, "font ms_sans_serif 10"
#main, "trapclose [QuitMain]"
#main.StatNumero,  "!font arial 9 bold"
#main.StatNom, "!font arial 9 bold"
#main.StatPrix, "!font arial 9 bold"
#main.ListItem "singleclickselect"
wait

sub sOpenDB
    open "database.dat" for random as #db len=150
    field #db,_
        40 as nom$,_
        10 as numero,_
        10 as prix ,_
        90 as reserve$
end sub

sub sReadDB
    totalRecords = lof(#db)/150
    maxItems = totalRecords + 1
    redim items$(maxItems)
    for record = 1 to totalRecords
        get #db, record
        'Ajouter «chr$(0)» pr afficher le premier champ ds la liste
        items$(record) = trim$(nom$); chr$(0); numero; chr$(0); prix
    next
    sort items$(),1,totalRecords
end sub

sub sCloseDB
    close #db
end sub

sub sDisplayItem handle$
    #main.ListItem,"selectionindex? index"
    #main.StatAffNom,word$(items$(index), 1,chr$(0))
    #main.StatAffNum,word$(items$(index), 2, chr$(0))
    num$= word$(items$(index), 2,chr$(0))
    #main.StatAffPrix,word$(items$(index), 3, chr$(0))
end sub

sub sCheckButton control$
    #main.ListItem,"selectionindex? index"
    choix$=mid$(control$,7)
    call sOpenDB
    select case choix$
        case "ButAjout"
            #main.ListItem,"selectindex " ;index
            nom$=word$(items$(index+1), 1,chr$(0))
            if  nom$="*" then
                notice "Sélectionne « * » et choisi l'option «Modifier»"
                call sCloseDB
                #main.ButAjout,"!Disable"
                exit sub
            else: call sAffiche "Ajouter un item", maxItems
            end if
        case "ButModif"
            if index >0 then
                get #db, val(num$)
                items$(index) = trim$(nom$); chr$(0); numero; chr$(0); prix
                call sAffiche "Modifier un item",numero
            else: notice "Sélectionne un item"
            end if
        case "ButEfface"
            if index >0 then
                totalRecords = lof(#db)/150
                get #db, val(num$)
                items$(index) = trim$(nom$); chr$(0); numero; chr$(0); prix
                nom$="*":prix=0
                items$(index) = trim$(nom$); chr$(0); numero; chr$(0); prix
                put #db,val(num$)
            else: notice "Sélectionne un item"
            end if
    end select
    sort items$(),1,totalRecords
    #main.ListItem "reload"
    #main.ListItem "selectindex 0"
    #main.StatAffNum, ""
    #main.StatAffNom,   ""
    #main.StatAffPrix,  ""
    call sCloseDB
    #main.ButAjout,"!Enable"
end sub

sub sAffiche caption$, itemNumber
    WindowWidth = 275
    WindowHeight = 195
    'position of dialogs are relative to previous open window
    UpperLeftX=1
    UpperLeftY=1
    statictext #item.StatNumero, "# de l'item:",  10,   7,  80,  25
    statictext #item.StatNom, "Nom:",    10,  42,  80,  25
    statictext #item.StatPrix,   "Prix:",   10,  77,  80,  25
    textbox #item.TextNum, 105,   7, 150,  25
    textbox #item.TextNom,  105,  42, 150,  25
    textbox #item.TextPrix,  105,  77, 150,  25
    button #item.ButFermer,  "Fermer",[QuitItem], UL,  95, 127,  63,  25
    button #item.ButAccepter, "Accepter",[Accepter], UL, 180, 127,  75,  25
    open caption$; " :  ==>  "; itemNumber for dialog_modal as #item
    #item, "font arial 10"
    #item, "trapclose [QuitItem]"
    #item.TextNum, itemNumber
    #item.TextNom,"!setfocus"
end sub

[Accepter]
    #item.TextNum,"!contents? tempoNum$"
    #item.TextNom,"!contents? tempoNom$"
    #item.TextPrix,"!contents? tempoPrix$"
    numero=val(tempoNum$):prix=val(tempoPrix$):nom$= tempoNom$
    items$(val(num$)) = trim$(nom$); chr$(0); numero; chr$(0); prix
    call sOpenDB
    put #db,numero
    call sReadDB
    call sCloseDB
    close #item
    #main.ListItem "reload"
wait

[QuitItem]
    close #item
    wait

[QuitMain]
    close#main:end
 
« Last Edit: Jul 21st, 2017, 10:43am by Rod » User IP Logged

Rod
Global Moderator
ImageImageImageImageImage


member is offline

Avatar

Graphics = goosebumps!


PM

Gender: Male
Posts: 5567
xx Re: remote button clic
« Reply #3 on: Jul 21st, 2017, 10:54am »

The program flow is entirely under your command. If you know you are adding a record and you have found a "*" then just proceed straight to the add code or modify code preserving the record number, don't bother with the notice message and forced redirection to modify.
User IP Logged

ombre
New Member
Image


member is offline

Avatar




PM

Gender: Male
Posts: 29
xx Re: remote button clic
« Reply #4 on: Jul 21st, 2017, 2:47pm »

The question and the problem is just that: how do I modifiy the code to preserve the id number and continue to the add item. I dont't want empty spaces in my database.
User IP Logged

Rod
Global Moderator
ImageImageImageImageImage


member is offline

Avatar

Graphics = goosebumps!


PM

Gender: Male
Posts: 5567
xx Re: remote button clic
« Reply #5 on: Jul 21st, 2017, 3:35pm »

Spaces, you mean empty records, but you do and they are identified by "*".

So if you find that you have a free record, "*", when the add button is clicked then use it, don't branch off to the notice and modify routine. Keep modify for modifying records, use add for add new or rewrite "*"

Not understanding why you see a blockage.
User IP Logged

ombre
New Member
Image


member is offline

Avatar




PM

Gender: Male
Posts: 29
xx Re: remote button clic
« Reply #6 on: Jul 22nd, 2017, 09:38am »

When you write "So if you find that you have a free record, "*", when the add button is clicked then use it"; the question from the beginning is HOW to use it without goiing to the modify routine.
User IP Logged

ombre
New Member
Image


member is offline

Avatar




PM

Gender: Male
Posts: 29
xx Re: remote button clic
« Reply #7 on: Jul 22nd, 2017, 09:54am »

Discard my last post: I found my answer.

Thank you
User IP Logged

Pages: 1  Notify Send Topic Print
« Previous Topic | Next Topic »

Rules|Home|Help|Search|Recent Posts|Notification

Donate $6.99 for 50,000 Ad-Free Pageviews!

| |

This forum powered for FREE by Conforums ©
Sign up for your own Free Message Board today!
Terms of Service | Privacy Policy | Conforums Support | Parental Controls