• Welcome to PlanetSquires Forums.
 

question about reading GUI form loading/reading text file values

Started by veltesian, July 23, 2020, 11:03:23 AM

Previous topic - Next topic

veltesian

hello everyone.... i was wondering about how can i program a button on a GUI form
to load values from a text file into 1 or more textboxes residing upon a GUI form.
if necessary, i could upload a project that had me stumped at & could not continue....
the only file that is not present with this project is a file that would connect internally
to it is called "a1.dat", which this forums system does not allow me to upload. the file
a1.dat that i have used with this project only contains 4 words within it:

apple
giraffe
truck
laptop

it was just a simple idea @ the start. but i would like to understand how to really
create more complexing database type situations for programming.

Petrus Vorster

Hi there

Do you just need to read information from a text file, then place that information in some text boxes?
Or do you need examples of some more heavy duty information in-and-out or actual databases?

-Regards, Peter
-Regards
Peter

veltesian

hello petrus ....

yes i need the GUI form to read data from a text file, then place that data in some text boxes?
also i was curious about if the GUI form i uploaded could be coded to search within a text file
for specific "chunks" or individual strings of data to display that amongst 1 or 2 textboxes
upon a GUI form. i had a thought that within the text file i might need to include certain
text markers that the GUI form could programmatically connect it so as to perform more
effectively. could you possibly help me with this ?

Johan Klassen

@veltesian
in your code you assign tx1 and tx2 empty strings, then you read values from a1.dat but you don't use them
you need to do things in sequence, read the data and then assign that to tx1 and tx2
I think that a better design would be to have one multi-line text box, here's my suggestion
delete tx2 and make tx1 taller
with tx1 selected goto the properties tab on the toolbox
make Multiline True
make TextScrollBars ScrollBars.Vertical
then change the Btn1_Click to something like

Function Form1_Btn1_Click( ByRef sender As wfxButton, ByRef e As EventArgs ) As LRESULT
    dim a as string
    Dim b as string
    dim NewLine as string = chr(13) + chr(10)
    dim i as long
     
    Open "a1.dat" For Input As #1
    i=0
    while not eof(1)
        Input #1, a
        if i=0 then
            Form1.Tx1.Text = a
        else
            Form1.Tx1.Text = Form1.Tx1.Text + NewLine + a
        end if
        i=i+1
    wend
    Close #1

    Function = 0
End Function

Petrus Vorster

I have attached you the most simple example
It will save three animals in a file and then the next row will retrieve those records from the file.
That is all.

But it will give you some idea where to start.
Then we can work from there.

Hope this helps
-Regards
Peter

Petrus Vorster

Are you just starting out with the Basic dialect or have you worked with some basic languages before?
The new classes here are powerful but one needs to know where you are at in Programming.
My example is really elementary, perhaps you were looking for something more advanced?

-Peter
-Regards
Peter

veltesian

hello petrus... i must confess, back in the mid to late 90s i had used the microsoft's visual basic 6 for learning.
(the classic version & NO dotnet framework involved) i just tried the example you provided, it works great...
it will be just fine. thanks for your help petrus its much appreciated. :D

veltesian

ok so i wanted to understand this topic about GUI data loading from a text file in a few
different alternate/possible ways. i also want to figure out how a GUI form could load
data from a text file but in a way like as if its a program loading data into multiple text
fields like a configuration or workspace file, or like a program loading data as in multiple
text boxes as previously saved settings. its like the equivalent of a digital form that could
allow you to fill in many fields, save those fields to a text file, then recall that file to also
edit those contents & then resave the form. if petrus & or johan are seeing this, i'm terribly
sorry i did not mention it in any earlier posts about this topic.


veltesian

please forgive me,.... a very special thank you also goes out to the user Johan Klassen.
thank you ever so much as well for the example solution you provided works great.
to both petrus & johan .... thanks a million!! its much appreciated. :D

Petrus Vorster

You should look into the option of different controls.
For example the Listview control is a tool i use in just about everything.

But I still work on Firefly3, i just started out in this new Gui myself.
If you need rows of information from files then the Listview would be my suggestion.

But we will need some help from the others here, I will have to go look it up myself first too.
Look at the image i provided, is this what you have in mind?
-Regards
Peter

veltesian

hello petrus.... & yes that image looks close to what i'm going for.
if a listview control can load data from a text file into its list view's fields
that is if it works that way. or if its like a listbox. sure i'd be willing to
take a look at 1 or more other/alternative controls if it would help me
get to find a solution that works.

i want to learn how to effectively use as many of the virtual/physical
controls as i possibly can.

veltesian

one recent thought... please pardon me everyone if this sound like something
i tried to ask about the same way before previously.....

what if i built a GUI that had 2 command buttons & a textbox or listbox (whichever one would be fine)
the first button could load a text file that has already filled with say 10 lines of data (mixed letters/numbers/symbols)
then a 2nd button to go & look into the text file & say, read from line 4 & extract from position 6 - 18
then transfer that data to a text or listbox

raymw

Hi,
use one button to load in the text file, but just to a list. No need for a list box at that stage. Then another button, and a text box, to search for whatever it is you need  in the list, then display what you find.
If you can post a bit of code, we may be able to suggest other ways of doing it.
If you are wanting to make a number of accesses to a file, it usually pays to read in the whole file to memory, and access the data from there. It has the added advantage that the original hdd file is untouched, until you want to save the altered data back, and then you can save as a different file name. These days there are far fewer restrictions on the size of data in memory.

Best wishes,

Ray

veltesian

hello ray ....

when i mentioned the below commentary ....

what if i built a GUI that had 2 command buttons & a textbox or listbox (whichever one would be fine)
the first button could load a text file that has already filled with say 10 lines of data (mixed letters/numbers/symbols)
then a 2nd button to go & look into the text file & say, read from line 4 & extract from position 6 - 18
then transfer that data to a text or listbox

i was meaning if someone could assist me with how to help me build this...
sorry that i did not include this in my last post. sorry about that ray. in the example
i was describing above, i was hoping to connect with anyone who could help me with
mainly the aspect of after the file is loaded.... that the GUI form could have a button
or some kinda of control to read the text file & then extract from any one certain line(s)
in the file & transfer perhaps a small portion of data (whether text/numbers/symbols/etc)
to a textbox upon the form. sorry about not being very clear on that.




raymw

Hi, Is this the sort of thing you want. use the designer to make a form, put on a button and two text boxes. in the designer toolbox select click event for button, and initialize event for the form.

then edit the generated code as below, say

' You should always include a resource file that references a valid manifest.xml
' file otherwise your application will not properly display Windows themed controls.
' Sample resource.rc and manifest.xml files can be found in the WinFBE \Settings folder.
' The following WinFBE directive includes the resource in your application. Simply
' uncomment the line.
' If you are using WinFBE's project management features then delete the following line
' because a resource file will be generated automatically.
'     '#RESOURCE "resource.rc"


''
''  Remove the following Application.Run code if it used elsewhere in your application.
Application.Run(Form1)

''
dim shared alist(10) as   string



''
Function Form1_Button1_Click( ByRef sender As wfxButton, ByRef e As EventArgs ) As LRESULT
   
  form1.text2.text=alist(valint(form1.text1.text))

   Function = 0
End Function

''
''
Function Form1_Initialize( ByRef sender As wfxForm, ByRef e As EventArgs ) As LRESULT
   
   alist(1)= "this is one"
alist(2)="2"
alist(3)="three"
alist(0)= "remember zero"
alist(7)= "a seven"
alist(5)= "not 7"
   ' and whatever else you may want to try.
   Function = 0
End Function


I've not bothered to show the button/code to read in a file, but loaded values when the form is initialised
I had the feeling you were stuck on getting a reference to the items from a text box value. Of course you can add in data validation, parse it to ensure it's a number, search for specific text whatever. by editing this one line ' form1.text2.text=alist(valint(form1.text1.text))' That line is converting the text in textbox1 to an integer and using that value as the index to the list. It is then placing the result into textbox2 as text. This occurs when the button is clicked.