Any Visual Basic wizkids in here?

  Elrond 17:52 16 Mar 2003
Locked

I am only a novice and have put together an application in which when opened (MDI PARENT FORM) has nothing but a menu across the top with the usual File-Edit etc options. In my file menu I have a New option like many other applications. This opens up a Child form with the main parts of the app on. What I need to do is be able to code my Save option in the file menu, to Save the details that the user puts into the form. Any Ideas? Thanks

  Taran 18:05 16 Mar 2003

What are the user details, where will they be saved (as or to a text file, into a database etc) and how are they inputting - standard textboxes for personal contact information for example, or are they selecting from listboxes from a series of options ?

Give as much information as you can. One of us will try and help.

  Elrond 18:19 16 Mar 2003

Well, what it is, you open the main window, then select new rabbit.(its a little prog for my gf's dad who shows rabbits). That then opens a new form which has details about the rabbit, Name/d.o.b/sex etc, and the user inputs this info into a text box

  Taran 18:38 16 Mar 2003

That sounds like an Access job rather than out and out VB.

Unless it absolutely has to be VB, I'd be tempted to make an Access (or similar program) database - you can program it from VB if you like.

Post again if you have to use VB, but from the little you have mentioned I'd say this is a small database project more than anything else.

  Elrond 18:43 16 Mar 2003

I havent the slightest idea how to use Access, I'm doin it thru VB cos I just wanted to create a few of my own programsplus I can design it how I want to, because I've divided the form to have a large text box on the one side just to add any miscellaneous detials. So what I was looking for was what code to add to this in the main code window


Private Sub mnuFileSave_Click()

End Sub

  Elrond 18:46 16 Mar 2003

My GF's dad is a complete new user with PC's so I have designed it to be real simple for him to use

  Taran 18:35 17 Mar 2003

I got sidetracked elsewhere. The code you ned will be something roughly along the lines of what I have listed below.

I have assumed that you are using a common dialog control and that you know how to set up the file formats in the filter section that you want to be able to save as (.txt, .rtf, .doc and so on).

Private Sub mnuFileSave_Click()

Dim sFile As String

If Left$(ActiveForm.Caption, 8) = "Document"

Then

With dlgCommonDialog

.DialogTitle = "Save"

.CancelError = False

'ToDo: set the flags and attributes of the common

dialog control

.Filter = "All Files (*.*)|*.*"

.ShowSave

If Len(.FileName) = 0 Then

Exit Sub

End If

sFile = .FileName

End With

ActiveForm.rtfText.SaveFile sFile

Else

sFile = ActiveForm.Caption

ActiveForm.rtfText.SaveFile sFile

End If

End Sub


Be advised that this will need some serious rejigging where object names for your form will have to be included, and it is clearly based on a rich textbox as the input medium, hence the ActiveForm.rtfText line. You also need to be aware that when using a common dialog control in your program you will have to distribute the CMDLG32.OCX file to your client (the girlfriends dad in this case) or the application will throw out an error. It needs to be installed/copied into the SYSTEM32 folder on the computer the program will be installed on. There are other ways of doing it, but these can get a little sloppy and running a simple compile from within VB sometimes doesn't do what nature intended. To be on the safe side, make sure you have a copy of the file (it's only about 133k).

If you are using API instead of Common Dialog, post back and I'll come up with some alternatives for you. Actually,\ if you're using API instead of Common Dialog, hats off to you for trying.

Finally, the reason I suggested Access is that as long as the system the application will be used on has Access installed, doing what you describe is right up the proverbial alley of a database program. It's also considerably easier than programming an application, once you understand a few simple fundamentals. All it would need from your description is to related tables (Owner table and Rabbit table) and a simple input form and some queries. Most of this can be reasonably done through the Access wizard of you don't know the program.

Hope this helps.

regards

Taran

  Taran 18:38 17 Mar 2003

I forgot about the formatting problem in here.

Try this instead:

Private Sub mnuFileSave_Click()

Dim sFile As String

If Left$(ActiveForm.Caption, 8) = "Document" Then

With dlgCommonDialog

.DialogTitle = "Save"

.CancelError = False

'ToDo: set the flags and attributes of the common dialog control

.Filter = "All Files (*.*)|*.*"

.ShowSave

If Len(.FileName) = 0 Then

Exit Sub

End If

sFile = .FileName

End With

ActiveForm.rtfText.SaveFile sFile

Else

sFile = ActiveForm.Caption

ActiveForm.rtfText.SaveFile sFile

End If

End Sub

  Taran 18:39 17 Mar 2003

That's better.

It at least makes sense now.

T

  Elrond 18:41 17 Mar 2003

Thanks Taran I'll give that a go as soon as I get a chance. Thanks again

  Taran 18:55 17 Mar 2003

My apologies for the appalling spelling above.

My fingers are stuttering this evening.

"to related tables" was obviously intended to be "two related tables" and the rest of the errors are spectacular enough to stand on their own merit.

Good luck with the code which, by some miracle, was correctly written.

T

This thread is now locked and can not be replied to.

Elsewhere on IDG sites

AMD Radeon Adrenalin release date, new features, compatible graphics cards

8 brilliant character artists speaking at Pictoplasma 2018

iMac Pro release date, UK price & specs

Football : comment regarder la Ligue 1 en direct ?