GAtkins

I would appreciate any help someone could give me.

I have searched this forum endlessly trying to find a way to save 60 or so text boxes on form1 to a file and then later read the information back into the same text boxes.

It seems like I have tried every bit of sample code that I can find and nothing works. I have 5 books on VBE and VB5.

I am a complete novice at this so please be gentle.

Thanks in advance for any ideas/help.

Glenn



Re: Visual Basic Express Edition so gentle

ReneeC

You why it's hard Probably because it's not a good Gui design.

If you said more about your application and what you need, it may be helpful.






Re: Visual Basic Express Edition so gentle

GAtkins

   Well let's assume I would use another type of GUI then.  What type would you suggest and how can I save and retrieve the user/data inputs to and from a file that is not beyond my abilities to accomplish

I am willing to learn and give anything a try, so please suggest.

To more specifically answer your question, I need to imput a name, a scenario name, a date, six asset ty pes, six asset amounts, six income amounts, six income types, and so on, up to about sixty different fields.

I then will write code that will conduct a Monte Carlo simulation of future stock returns with say 50 years and up to probably 10,000 iterations in each year.  this will output random, ending portfolio values and return a probability of not running out of money in each year.

Multiple distributions can be selected such as normal, log normal and exponential, with the log normal one using a Box Mueller transformation.

Beyond that, I want to draw some pretty graphs too.

I have already accomplished this in Excel VBA, but want to port it to VB to make it more polished and for the challenge of doing it.

Thanks

Glenn





Re: Visual Basic Express Edition so gentle

ReneeC

Well let's assume I would use another type of GUI then. What type would you suggest and how can I save and retrieve the user/data inputs to and from a file that is not beyond my abilities to accomplish


I cant speak for your abilities, but what you are proposing is going to require a lot of computational expertise. Youve mentioned several issues, so lets consider data issues first and then the GUI issues.

What you have described is unlikely to be meaningfully resolved with any kind of flatfile solution. I do not know how many sets of data you are proposing. If its just a few, then an XML file, written by the XML writer may be of interest. An XML file is a self-describing hierarchically organized data system, readable with Notepad. Internally an XML file looks like this:

< xml version="1.0" encoding="utf-8" standalone="yes" >
<Directory>
<Service>
<ServiceName>Abuse and Neglect Services</ServiceName>
<Description>Help for an abused or neglected child</Description>
<Para1>The organizations listed below provide services for abused or neglected children and their families.</Para1>
<Para2>For each of the organizations listed below you will find information about the ages they serve, the languages spoken and eligibility criteria.</Para2>
<Para3>More complete information about these organizations's location, contact person, hours of operation and a description of their programs can be found in Part II - Directory of Organizations starting on page xx.</Para3>
<Narrative>More complete information about these organization's locations, contact person, hours of operation, fees charged and a description their programs can be found in part II, the directory of organizations starting on page PAGENUM</Narrative>


<ServiceDetail>
<SrvDetail>General</SrvDetail>
<Organization>
<Organization-Phone>Associates For Renewal In Education (555) 111-9424</Organization-Phone>
<Ages>2-6; 7-12; 13-2(Also adults)</Ages>
<Languages><![CDATA[English;]]></Languages>
<Eligibility><![CDATA[All]]></Eligibility>
</Organization>
<Organization>
<Organization-Phone>Center for Adoptive Families (of AdoptionsTogether, Inc.)* (555) 111-2900</Organization-Phone>
<Ages>0-6; 7-12; 13-18</Ages>
<Languages><![CDATA[Portuguese; Spanish]]></Languages>
<Eligibility><![CDATA[Children and their families affected by adoption or foster\line care]]></Eligibility>
</Organization>
<Organization>
<Organization-Phone>Center for Child Protection and Family Support, Inc. (555) 111-6175</Organization-Phone>
<Ages>4-6; 12; 13-17</Ages>
<Languages><![CDATA[English]]></Languages>
<Eligibility><![CDATA[Child victims of neglect, physical abuse, sexual abuse or\line with a report from the police regarding child abuse or\line neglect. ;]]></Eligibility>
</Organization>
<Organization>

As you can see, XML supports replicated entities quite well and be well suited to your application if there is not a large number different sets of data, like Agency A, Agency B, etc. Variables are known by labels. If there is, I think a database is indicated be it either Access or SQL Express.

So lets talk about a GUI solution. The interesting thing about this was that all the data was entered via a single textbox. We know the questions will be the same for each Organization so I was write software that know how to prompt for the data and to collect it.

Each question has a structure associated with that systematically prompts the user for information. Descriptors for doing that might look like this:

InqArray(ciOID).DBModifiableField = False

InqArray(ciOID).MandatoryField = False

InqArray(ciOID).UserModifiableField = False

InqArray(ciOID).CmbIndex = -1

InqArray(ciOID).DisplayAsChoice = False

InqArray(ciOID).[Protected] = True

InqArray(ciOID).DBFieldName = "O_ID"

InqArray(ciOID).ControlType = Cntrltyp.None

TextBoxTemplate.DBModifiableField = True ' Set up the template

TextBoxTemplate.MandatoryField = False ' Make the default - User's Options to fill in the form

TextBoxTemplate.ControlType = Cntrltyp.Textbox

TextBoxTemplate.UserModifiableField = True

TextBoxTemplate.DisplayAsChoice = True

TextBoxTemplate.tbmaxlen = 50 ' in characters

TextBoxTemplate.tbNoofLines = 1 ' 20 pixels perline

InqArray(ciName) = TextBoxTemplate

InqArray(ciName).tbmaxlen = 100

InqArray(ciName).CmbIndex = 0 ''

InqArray(ciName).MandatoryField = True

InqArray(ciName).Name = OrgFields(0)

InqArray(ciName).Instruction = "FQLR|'s Name."

InqArray(ciName).DBFieldName = "O_Name"

InqArray(ciContact) = TextBoxTemplate

InqArray(ciContact).CmbIndex = 1 ''

InqArray(ciContact).Name = OrgFields(1)

InqArray(ciContact).MandatoryField = True

InqArray(ciContact).Instruction = "FQLR|'s contact person's name."

InqArray(ciContact).DBFieldName = "O_Contact"

InqArray(ciAddress) = TextBoxTemplate

InqArray(ciAddress).CmbIndex = 2 ''

InqArray(ciAddress).Name = OrgFields(2)

InqArray(ciAddress).MandatoryField = True

InqArray(ciAddress).Instruction = "FQLR| street address."

InqArray(ciAddress).DBFieldName = "O_Address"

As you can see this structure supplies information for prompting the user as well as collecting and storing the data. Once its all collected its committed to the database.

There were also back and forward controls to allows the user to go back and make corrections. These suggestions I think would suit you well.






Re: Visual Basic Express Edition so gentle

Tall Dude

See my reply at

http://forums.microsoft.com/MSDN/ShowPost.aspx PostID=1224757&SiteID=1

Change the term 'radiobutton' to 'textbox' and

change the term 'checked' to 'text'.






Re: Visual Basic Express Edition so gentle

ReneeC

I think you missed the boat on this one. He has a lot of data storage from what I gather.






Re: Visual Basic Express Edition so gentle

GAtkins

Tall Dude,

Thanks. That worked great. But perhaps I am not being clear. I need to enter a bunch of data into these text boxes. Then click a button like Run Simulation and do the aforementioned calculations and return some results.

Then I need to save this entire project to a unique file name such as Joe Smith Base Case Scenario.(some extension).

Then of course, I need to be able to open the file with the saved data, etc., make changes, re-run the simulation if necessary and then resave.

Then in another file would be the John Jones Base Case Scenario, for example.

Think of it almost like Excel. Enter some data, do some calculations, save data and results, retrieve, change inputs, repeat.

Any other ideas

Thanks in advance.

Glenn





Re: Visual Basic Express Edition so gentle

ReneeC

a database...........






Re: Visual Basic Express Edition so gentle

Behrooz PB

u r so gentle reneeC, I`m not keeding.

Go On and Go On and Go On

I am learning all my seconds in programming, But now I am thinking to learn some of your cyber behaviours.

Thanks U and all Top Answerers . . .

 





Re: Visual Basic Express Edition so gentle

GAtkins

Of course I realize that a "database" is a good conceptual tool, but that is very different than a solution. What I need is a solution to the question I asked, please.

I have only been hanging around here a couple of days. As I mentioned in my original post, my ablities are very limited at this point, however I am trying to learn. I buy books, I search the forums, I watch the videos and then I come to the experts her for help. Is there another approach

Maybe this project is too difficult to attempt for such a novice, but I doubt it. As I mentioned, I have already done this in Excel VBA. I am really tired of coding and running "Hellow World!"

So, back to the topic at hand. Can someone please explain to me an easy and efficient way of saving a series of text boxes on a form in a file name and the retrieving that file later

I would be grateful if it was an actual example presented in a way that I could actually understand it.

Thanks

Glenn





Re: Visual Basic Express Edition so gentle

ReneeC

Well... I'll step out. You see, I think your intital approach is not that great and it's going to cause you problems and you will end up building a bi-plane.

Why not take it a step at time. Break your problem up into small discrete steps. The first thing I would do would be an intelligent gui design where you collect the data to fill a row in a database. Once you have that, design the database or even vice-versa.

The reason I'm saying this is that I've been dealing with problems like this for the last forty years. You are new to this. Anyone can also ask a question that's going to lead them down the river and then insist on re-asking it OR you can actually listen. It's up to you.






Re: Visual Basic Express Edition so gentle

GAtkins

ReneeC and others:

I am totally listening. I simply do not know how to do what you are suggesting.

I like to go down the river the correct way on a nice, new fancy boat. I just don't know how.

Can you suggest somewhere I can learn the appropriate steps to an intelligent GUI and how to do the database stuff

I really am trying to learn. Oh and don't step out. I see the many valuable contributions you make.

Many thanks.

Glenn





Re: Visual Basic Express Edition so gentle

Siddarth Chordia

First thing... Give the same name to all text boxes n when it asks for you to put it in an array for the repetition of the name when you are giving the same name the second time just click yes... next time onwards when you give the same name to other text boxes it will not ask you n it will automatically take it in an array ... Now using the code open the table of the data base and using the for loop like this

for i = 0 to 59

    <tablename>.field(i).value = <text box name>.text

next

N this three lines of code will save the data for 60 text boxes You need not write the code for 60 text boxes..... if any doubts you can ask me........






Re: Visual Basic Express Edition so gentle

ReneeC

He doesn't have a table yet. He doesn't have a database design yet. Give me an hour to let me look at the GUI.






Re: Visual Basic Express Edition so gentle

ReneeC

Ok, here's is a good model using a single text box - Discussion follows in the next post

Public Class Form1

Private DataDict As New Dictionary(Of Integer, String)

Private InstructionDict As New Dictionary(Of Integer, String)

Private CurEntNo As Integer : Private Mode As String = ModeEnter

Const ModeEdit As String = "Edit"

Const ModeEnter As String = "Enter"

Private IgnoreChange As Boolean

Private Sub Form1_Load(ByVal sender As Object, _

ByVal e As System.EventArgs) Handles Me.Load

LoadInstructionDictionary()

IgnoreChange = True

For i As Integer = 0 To InstructionDict.Count - 1

cmbxEdit.Items.Add(InstructionDict.Item(i))

Next

IgnoreChange = False

Reset()

End Sub

Private Sub Textbox1_KeyPress(ByVal sender As Object, _

ByVal e As System.Windows.Forms.KeyPressEventArgs) _

Handles TextBox1.KeyPress

'The following properties must be set thusly:

If e.KeyChar = Chr(Keys.Enter) Then

Select Case Mode

Case ModeEnter

DataDict.Add(CurEntNo, TextBox1.Text)

If CurEntNo = InstructionDict.Count - 1 Then

' we're finished Entry

cmbxEdit.Visible = True

Mode = ModeEdit

' Enable your future commit button for committing
to the database

Exit Sub

End If

CurEntNo += 1

Label1.Text = "Enter " + _

InstructionDict.Item(CurEntNo)

TextBox1.Clear()

Case ModeEdit

DataDict.Item(CurEntNo) = TextBox1.Text

Label1.Text = InstructionDict.Item(CurEntNo) + _
" Updated"

TextBox1.Clear()

cmbxEdit.Text = ""

End Select

e.Handled = True

End If

End Sub

Private Sub Reset()

CurEntNo = 0

DataDict.Clear()

Label1.Text = "Enter " + InstructionDict.Item(0)

Mode = ModeEnter : cmbxEdit.Visible = False

End Sub

Private Sub LoadInstructionDictionary()

InstructionDict.Add(InstructionDict.Count, "Date")

InstructionDict.Add(InstructionDict.Count, "Area")

InstructionDict.Add(InstructionDict.Count, "Company")

InstructionDict.Add(InstructionDict.Count, "Price")

InstructionDict.Add(InstructionDict.Count, "Modeling Type")

End Sub

Private Sub cbReset_Click(ByVal sender As Object, _

ByVal e As System.EventArgs) Handles cbReset.click

Reset()

End Sub

Private Sub cmbxEdit_SelectedValueChanged(ByVal sender As Object, _

ByVal e As System.EventArgs) _

Handles cmbxEdit.SelectedIndexChanged

If IgnoreChange Then Exit Sub

CurEntNo = cmbxEdit.SelectedIndex

Label1.Text = "Enter " + InstructionDict.Item(CurEntNo)

TextBox1.Text = DataDict.Item(CurEntNo)

End Sub

End Class