Link to home
Start Free TrialLog in
Avatar of netstallone
netstallone

asked on

How Do I Save My Application/Form In The Format As It Is On Hard-Drive??

Hello,Sir
Actually i'd made a project regarding my teacher's profile where i've 1-form containing & if you want to see in more detail format i can zip it to your email add. so that u can have a idea of it,Anyway below i've mentioned all details:-

This Form has background color which insert from properties->picture;also
labels,textbox,combo box are all in different color( properties->background).
Now when i save this form in this format which is stated above; but when its saved it is in plain text without picture & colors.What i want is it should be saved with color textbx,combbx,& pic's with background color.So that when i upload this form my teacher's{Users} can save it on their hard-drive.It's Something  like this as stated below??


Label                                       Textbox      
1)Teachers Name                  Text1
2)Subjects                               Text2
3)Email-id                             Combo-box                    & one Picture box

This above form also has 2-command buttons ( Saveas,Preview)
I've all the codings for all of this but i want to save my form in as it is format including colors & picture.

Below is the coding:

Private Sub Command1_Click() 'Preview button
Form2.Show
End Sub

Private Sub dir1_change()
File1.Path = Dir1.Path
End Sub

Private Sub Drive1_Change()
Dir1.Path = Drive1.Drive
End Sub

Private Sub File1_Click()
Dim sPath As String
If Right$(Dir1.Path, 1) = "\" Then
    sPath = Dir1.Path & File1.FileName
Else
    sPath = Dir1.Path & "\" & File1.FileName
End If
Set Picture1.Picture = LoadPicture(sPath)
End Sub

Private Sub Form_Load()
File1.Pattern = "*.bmp;*.gif;*.jpg"
End Sub




Option Explicit

Private Sub Command2_Click()
Dim Filter As String
Dim strFileName As String 'String of file to open
Dim strtext As String 'Contents of file
'Dim strFilter As String 'Common Dialog filter string
Dim strBuffer As String 'String buffer variable
Dim FileHandle% 'Variable to hold file handle

On Error GoTo SaveAsError

Filter = "all files (*.*)|*.*|"
Filter = Filter + "HTML Files(*.htm)|*.htm|"
Filter = Filter + "Text Files(*.txt)|*.txt|"
Filter = Filter + "Batch Files (*.bat)|*.bat|"
Filter = Filter + "Document Files (*.Doc)|*.Doc|"
CommonDialog1.Filter = Filter
CommonDialog1.ShowSave
CommonDialog1.FilterIndex = 2
CommonDialog1.Action = 2

If CommonDialog1.FileName <> "" Then
'If it is not blank, open the file
strFileName = CommonDialog1.FileName
strtext = Text1.Text
FileHandle% = FreeFile
Open strFileName For Output As #FileHandle%
MousePointer = vbHourglass
Print #FileHandle%, strtext
MousePointer = vbDefault
Close #FileHandle%
End If
Exit Sub

SaveAsError:
MsgBox "you canceled the dialog box"
Exit Sub
End Sub



Private Sub Form_Load()
Form2.Picture1.Picture = Form1.Picture1.Picture
Form2.Text1.Text = Form1.Text1.Text
Form2.Text2.Text = Form1.Text2.Text
Form2.Combo1.Text = Form1.Combo1.Text
Form2.Combo2.Text = Form1.Combo2.Text
Form2.Combo3.Text = Form1.Combo3.Text

End Sub

Thanxs 4 ur Valuable Time.

Regards,
Netstallone.






Avatar of RichW
RichW
Flag of United States of America image

I'm afraid I don't understand what you're actually trying to do.

Are you saying that you want the VB form to save, or a a file generated by the application?

If it's the latter, which format are you choosing SaveAs?  HTML, Doc?





Avatar of Mike McCracken
Mike McCracken

VB saves forms as text descriptions which are then interpreted by the IDE and presented to the user as graphics with colors.

If you are trying to save the form as a picture you can bring the form up do a Print Screen which copies the screen to the clipboard.  You can then paste the picture into any progam you want like Word or Paint.

If this isn't what you want please be more explicit.

mlmcc
Avatar of netstallone

ASKER

actually i want to save it in text file format as it's exe file;but when saving that text-file it saves the input content as plain without colors & pic's.kindly informe as to what to do for coding with this;so that user can save their data as it iswith color textbx,combo-box as well as pic's.This is very urgent cause i want to submit the project very soon?
If you put a picture into the form using the property box and the Picture property, then generally a separate file is created by VB with the same name as your form, but, instead of a .frm extension, it has a .frx extension.  You should always keep these two files together.  Then, when the form is added to a new project, as long as the FRX is present, the background image will be present.  The .frx file is a binary file, so, browsing it wont do you any good.
To let my application display where should i save on it?Will it be on  html or doc;cause i just want that to be saved as it is & user can also easily save this to there drive?so what is the code for saving on Html/doc.
My ultimate aim is to save it with all the contents in as it is format ,whichever may be extension.Be it a html or doc;i wish if i can  mail u & show u my project so that u can be more clearer & precised.

Regards,
Netstallone.
My ultimate aim is to save it with all the contents in as it is format ,whichever may be extension.Be it a html or doc;i wish if i can  mail u & show u my project so that u can be more clearer & precised.

Regards,
Netstallone.
My ultimate aim is to save it with all the contents in as it is format ,whichever may be extension.Be it a html or doc??
Netstallone.
OK, I guess I'd misunderstood your question.  If you have a VB form, you can't "save" it as an HTML or DOC, as there is nothing really to save.  It's not like a Word Document that can be saved in different formats.

If you want to produce an HTML document or a Word Document from the contents of your form, then you will have to create that document from within your code and format it to have the appearance and data that exists on the form.  But that takes a lot of work.  You can take a screen print of your form, and turn that into a .BMP image file, but that is about it.

What most people do when they want to print or save the contents of their form to a file like html or doc is they create a report using a reporting tool such as crystal reports, and then they run the report from inside of the application.
What i want is it should be saved & i don't want this to be done in database;i thought till now it would have been solved but still its unclear whether anyone can help me out from this.i've made a project which should be saved as it is in that exactly format with labels made in color,background color,textbx color....whole appl/form should be saved in that very format so that user can upload this on their drive??i guess this time i finally get the codes for my saving;Anyway above is the full details of my project & it's codes.

Netstallone.
ASKER CERTIFIED SOLUTION
Avatar of mdougan
mdougan
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Hello,Mdougan

I've developed a project which i want it to be used by user as a software,which enables any user to download on to their hard-drive whether they have a VB or not.My question is  that my application which i'd made to be saved on drive ( whole form/app. including backgroung color,textbx color....) It's exe.file o.k now when i write any input or fill the content in my text-box it displays in plain format only & i don't want this to happen;what i require is my exe.file should be saved as it is as i 've made. For example you make a software in Vb regarding your personal diet chart withbackground-col, color txt-bx,col-labels,col-combobx with picture bx,command button......fine then you convert this to exe.file;now if you want to launch this software how can any user download this with all the details including the above mention list.Only the thing where i've got stuck is saving my software/application;The important thing after converting my application to exe.file it's in a same format with all those colors & other properties;but when i write something in the textbx or combo-bx its displaying in plain format.This is where i need to explore more & i expect that you'll provide me all the needed code function  furthur required.Hope you'll guide me.

I wish this time it works,
Thanxs,
Netstallone.
OK, there may still be some terms that are being used that are confusing, but I'll try to clarify them.

If you make an EXE and you want to allow a user to download this EXE and run it on their machine, and they may or maynot have VB installed, then, you will need to create an Installation program using the Package and Deployment Wizard.

If you go to your Visual Studio Menu, you should see a Tools menu, and then on the tools menu, you will see a Package and Deployment item.  Choose this.  When the first screen comes up, it will ask you to choose your visual basic project, so, navigate to your program's .vbp file.  Then, it will ask what do you want to do, you will want to click on the option that says Package.  Then, on the next screen say that you want to create a Standard Setup Package.  Tell it where to save the setup files (usually this is a subdirectory called Package under your normal project directory).  You may get some messages about files or dependency information not found.  Do your best to answer any questions, but if in doubt, just click OK.

Then, you'll get a list of all of the files that the Wizard thinks you will need to distribute in order for your program to run on a computer that doesn't have VB.  If you know that you need some other files, like if you have some text files, or database files or Word document files that also need to be distributed with your program, you will need to add them at this time by clicking the Add button.  Then, you can pretty much just keep clicking the Next button until it is finished.

When it is done, there will be a few files, Setup.exe, Setup.lst, [your project's name].cab.  You will need to zip up these files and let the user download that zip file, expand it and then run the Setup.exe

Or, if you have the option when running the Package and Deployment Wizard, you might be able to choose a package type of Web Installation, in which case, it might create a CAB file this is commonly used when downloading/installing from the web.  Then,  you'd just have to put this file up on your website.

OK, now, once the user has your EXE and other necessary files installed, they can run your program.  They should see your form exactly as you designed your program, however, if you have used "system colors" to design your forms and fonts, then it's possible that one of these clients will have selected a different color scheme for their windows, and so your application will appear much different than the way you designed it.  If you want all users to see your form background as blue (or whatever), then you have to make sure to select the color blue from the form's color palette.  By default, VB sets all colors to system default colors, all fonts to default fonts and font colors.  So, unless you specifically set these to the colors you want, they might look different depending on the user.  So, if you want a textbox to have a red background with white text, then you will have to set the textboxes background to Red by choosing it from the textboxes background color palette, and you will have to set the forecolor from the textboxes forecolor color palette.  Then, all users will see those same colors on the screen.

Now, as far as text that is entered into a textbox, in VB, a standard textbox cannot display any special text formatting.  The text can only be one color, one font, one font setting (bold or not) (Italic or not).  If you want the user to be able to see certain words that have been set to the blue color, certain words set bold, certain words set italics, then you will have to use the Rich Textbox Control instead.  This is where I'm not sure what you are hoping to do, maybe I've helped to clarify some of your question.  Please, if you still are not sure, let me know what you are still not sure about.
Thanx Mdougan,
i'll go try this & i be intouch soon!
Hi,Mdougan

I understood installation process but still i want that when user open this software,they input data's & picture according to it & should be saved but don't know where to save as iam not using database to save it.I want user to save their data's & retrive it, which is displayed in that software whenever they want including
labels,rich text-box,combo-bx,background color,picture........
Now the saving data's format can be anything.So let me know how can i give coding for saving this function without use of database.

I'll be glad if this is solved cause the project is almost complete;And as soon as i get the saving coding i can submit.

Regards,
Netstallone.
OK, now I finally understand :)  Sometimes I'm a little slow.

You have a few options, depending on what you want to allow them to save.  If they are saving a setting, such as a font or a color, or label text, then it's probably best to let them save this information in the registry.  This can be easily done using the VB commands GetSetting and SaveSetting.  So, for example, when you load a form, you might have some code like this:

In a bas code module put these two functions:

Public Sub GetFormSettings(frm As Object)
Dim sWindowState
   
    On Error GoTo ErrorRtn
   
    sWindowState = GetSetting(App.Title, frm.Name, "WindowState", "MAXIMIZED")
   
    If sWindowState = "NORMAL" Then
        frm.WindowState = vbNormal
        frm.BackColor = GetSetting(App.Title, frm.Name, "BackColor", frm.Backcolor)
        frm.Top = GetSetting(App.Title, frm.Name, "Top", 0)
        frm.Left = GetSetting(App.Title, frm.Name, "Left", 0)
        frm.Height = GetSetting(App.Title, frm.Name, "Height", Screen.Height * Screen.TwipsPerPixelY)
        frm.Width = GetSetting(App.Title, frm.Name, "Width", Screen.Width * Screen.TwipsPerPixelX)
    Else
        frm.WindowState = vbMaximized
    End If
       
ExitRtn:
    Exit Sub
ErrorRtn:
    DisplayError "GetFormSettings", Err.Number, Err.Description
    Resume ExitRtn
End Sub

Public Sub SaveFormSettings(frm As Object)
Dim sWindowState
   
    On Error GoTo ErrorRtn
   
    If frm.WindowState = vbNormal Then
        sWindowState = "NORMAL"
    Else
        sWindowState = "MAXIMIZED"
    End If
   
    SaveSetting App.Title, frm.Name, "WindowState", sWindowState
    SaveSetting App.Title, frm.Name, "BackColor", frm.BackColor
    SaveSetting App.Title, frm.Name, "Top", frm.Top
    SaveSetting App.Title, frm.Name, "Left", frm.Left
    SaveSetting App.Title, frm.Name, "Height", frm.Height
    SaveSetting App.Title, frm.Name, "Width", frm.Width
ExitRtn:
    Exit Sub
ErrorRtn:
    DisplayError "SaveFormSettings", Err.Number, Err.Description
    Resume ExitRtn
End Sub

Then, in the Form_Load event of a form, just say:

GetFormSettings Me

and, in the form_unload event, just say:

SaveFormSettings Me

These routines save the position and size of a form when the user closes it, and the next time they open it, it will be positioned in the same place and be the same size.  I also added the code for saving and restoring the background color.  Now, it's up to you to provide the functions necessary that allow the user to actually set the colors or text.

You can save any "settings" in this way, including lable text.  The syntax for the SaveSetting function is:


SaveSetting [program name], [object name], [property name], [value]

So, if I were going to save the contents of a label's caption, I'd code it like this:


SaveSetting App.Title, "lblEmpName", "Caption", lblEmpName.Caption

Then, when Getting the value at form_load time, the syntax for the GetSetting function is:

RC = GetSetting([program name], [object name], [property name], [default value])

So, I'd code it like this:

lblEmpName.Caption = GetSetting(App.Title, "lblEmpName", "Caption", "Employee Name:")

The very first time your form is shown, all of the calls to GetSetting will return the default values.  However, if the user changes the caption, then when SaveSetting is called at Form_Unload time, then from then on, anytime GetSetting is called, the last value Saved will be returned.

The registry can be used for saving small amounts of text, such as label captions, but it should not be used for large amounts of text, like a document or a paragraph.  The registry also cannot be used to save photographs.  In that case, you should have a sub-directory under your application directory called something like Documents.  And, in the form_unload, you can have code like:

    SavePicture picEmployee.Picture, App.Path & "\Documents\picEmployee.bmp"

And in the Form_Load event you'd have code like:

   picEmployee.Picture = LoadPicture(App.Path & "\Documents\picEmployee.bmp")

Well, hopefully, this will get you started.  Write back if you have more questions.....

Hello,Mdougan
i tried everything u provided but it's not saving;i hereby request you to provide me ur email id so that i can send u my project & u can have idea as to what i'm trying to get maybe i'd not explain the way i want but i'm in desperate situation?i hope u'll understand this so that now i'll zip u my project to your email:id

Urgent,
Netstallone
OK, e-mail to mdougan@earthlink.net and I'll look at it tonight.
OK, I sent the project back to you.  Your code looked pretty good, I just modified it so that you are saving the contents of all of the controls to the text file.  You were only saving the contents of Text1.

Also, I added a routine to the first form that allows you to read in the file that you saved, otherwise, how do you know that the file save worked?

As far as saving the picture is concerned, in this case we're just saving the path to the picture, so that it can be loaded back in.  But, if you actually wanted to copy the picture and save it somewhere else, then you'd have to open up another SaveAs dialog, and then use the SavePicture function to save the picture to the new file location.
Hi,Mdougan
i recieved your mail & everything is fine but if u can make little furthur regarding the saving concept which is it's not storing the picture & i don't want to put xtra saveas command button;& second important thing is can't the application be saved directly as u made in load form why? i'm asking this cause if i'd to send this profile to other user how can he open this if he don't have this software or vb.as its saving first in plain format & then when load it saves as i required that's absolute fine but exactly in that format i want ot save it directly cause what's the use if can't send this to other person.I hope u got my point & expect u'll solve this also;but do remember to provide me the coding for saving my picture in that same application??

Thanxx so much for helping me i really appreciate u for this from bottom of my heart mr.mdougan?i'd attaching my project & mailed to your email-id-please check for my sake.i'll not trouble u anymore if this is solved.

Regards,
Netstallone.
Netstallone ->  You posted a question in Community Support requesting that we delete this question.  Clearly, all the help you have been given here does not merit a deletion, but a THANK YOU with an A grade and points awarded for the help given.

Listening further.

Moondancer - EE Moderator
I suggested that he delete this question as it finally became clear that what he really wants to do is to take the contents of a form and put it into a word document.  I suggested a rewording of his question and that he delete this one and post a new one so that people wont be lost in the thread.
I finalized this and awarded points to mdougan for help given here, but I also gave the points back to netstallone by adding them to Available points so this can be asked again.  This question was essentiall "free" for netstallone.

Moondancer - EE Moderator