[2008] Few Basic Questions
Alright, I've searched the web for a while now but I can't seem to find information to these questions:
1) Does one form house all the tools and hide/show them when needed or do I call up other forms when needed?
2) Can't find a good tutorial on VB databases
3) Lastly, how could I read information from a .txt file and when displayed on the form somehow place pictures within the text at designated points. (Basically making a walkthrough with pictures to demonstrate)
Thanks in advance.
Re: [2008] Few Basic Questions
1. That depends entirely on what you have for controls, how many there are, and for what they are being used. Your up front program design will dicate how many forms you will be using.
2. Go through our Database FAQ section.
3. You can display pictures in a richtextbox after reading a text file into it. However, if you save the richtextbox back to a text file, all graphics will be lost.
Re: [2008] Few Basic Questions
1. A form will control/house all the controls you place on it. If you dont add any controls to it then it will have none.
2. DB Forum FAQ link - http://www.vbforums.com/showthread.php?t=337051
3. Not sure on what you really are trying to do but you could use a picturebox control and a label control to load the data into. What kind of layout/design are you looking for?
Re: [2008] Few Basic Questions
Thank you for answering the first two, for the third I think it may just be easier to load an .html file for the guide instead of making it from a text file.
However I uncovered one more question.
First, currently I'm using this code to switch between forms
Code:
Private Sub idb_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles idb.Click
itemdb.Show()
Me.Hide()
End Sub
The question with this is a) is it good protocol and b) can you close a form without closing the program?
Thanks for your help so far.
Re: [2008] Few Basic Questions
Using .Hide wil not close the form but only hide it from display which will keep a program open still if that form is your startup object.
If your form is not going to be used again then .Close it is best so it frees up the resources.
Re: [2008] Few Basic Questions
Now the problem I'm having is that I want the web browser control in the form to load a webpage on the harddrive. However seeing as I want thsi to work on multiple computers I can put an absolute address in there. But as far as ive tried, I cant get a relative address to work. Any suggestions?
Re: [2008] Few Basic Questions
Are you using Application.StartupPath prepended with your html file name?
Re: [2008] Few Basic Questions
I googled that and I think I figured out how to do what you were asking,
Code:
Dim value As String
value = Application.StartupPath
Me.WebBrowser1.Navigate(value + "qlistm.html")
However in debug it doesnt work and (for now) im not sure if it prepended it correctly.
Re: [2008] Few Basic Questions
When working in the IDE your startuppath will be the location of your build. Usually in your projects "bin\Debug" directory. Verify that you have your html file in that directory
Re: [2008] Few Basic Questions
Thanks alot for thhe information so far! For now it will work, however what directory should the file be in for when I publish it?
Back to databases, I still can't work them the way I want, that is, having it display one item from x column at a time in a text box. So far I have this, but it's more me trying to frankenstein something together then actually knowing what it does.
Code:
Dim ds As DataSet
Dim strSQL As String = "SELECT [Name], [Location], [Price], [Quest Item] FROM [Items]"
Me.ItemsTableAdapter.Fill(Me.Database1DataSet1.Items)
name1.Text = Me.Database1DataSet1.Items.Tables(0).Rows(0).Item("Name").ToString()
New question: Can BASIC search strings and remove portions of them like c++? (Im looking to make a html parser)
Re: [2008] Few Basic Questions
The file would be in the same directory as the exe. The exe is the "Application" so when you access its .StartupPath" property it will be the full path to where the exe resides.
If you wanted you could contain the file in a subdirectory for a cleaner isolated look but it would be for looks only.
Re: [2008] Few Basic Questions
With a windows forms application I dont see an .exe when I publish it, just a autorun, setup, and application manifest, and in teh fodler created in Program Files, a application refrence.
Re: [2008] Few Basic Questions
you dont publish if you want an exe, you build :)
Re: [2008] Few Basic Questions
Oh you are using Express. I dont use it much at all lol. Use the Build menu to compile the exe and then you will need to decide on how you want to distribute it by Publishing it or using ClickOnce to build an instalation package.
Re: [2008] Few Basic Questions
Quote:
Originally Posted by RobDog888
Publishing it or using ClickOnce to build an instalation package.
Publishing does build a ClickOnce installation package.
Re: [2008] Few Basic Questions
Oi, I found an .exe file in bin\debug but it open in VB by default so im guessing thats not it?
EDIT: Didn't find an .exe but I found an application that seems to work.
Re: [2008] Few Basic Questions
One problem I've noticed though, is that when I open up a different form and hide the main one, and then close that different form, it doesn't show the main form or close the program. Any suggestions?
Re: [2008] Few Basic Questions
Let's say you have 2 forms: frmOne and frmTwo. frmOne is the main form.
On frmOne there is a button: btnShowTwo.
frmOne:
vb Code:
Private Sub btnShowTwo_Click(ByVal sender As object, ByVal e As System.EventArgs) Handles btnShowTwo.Click
Dim frmShowTwo as new frmTwo(Me)
frmShowTwo.Show()
Me.Hide()
End Sub
Now on frmTwo we need to tell it that when it is closing it needs to reShow the main form.
frmTwo:
vb Code:
Dim OriginalForm as Form
Public Sub New(ByVal CallingForm As Form)
MyBase.New
InitializeComponent()
OrginalForm = CallingForm
End Sub
Private Sub frmTwo_FormClosing(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs)
'this will close the frmTwo object
OriginalForm.Show()
End Sub
Re: [2008] Few Basic Questions
Just call ShowDialog instead of Show:
vb.net Code:
Me.Hide()
SomeForm.ShowDialog()
Me.Show()
Tada! ShowDialog doesn't return until the form is dismissed so you can simply show the caller again immediately
Re: [2008] Few Basic Questions
Alrighty, thanks.
However I'm still having the hardest time finding something on databases. Using MSDN tutorials I got some tool in there but it wasn't really what I wanted.
Basically I just want to take info from the database and place it into a textbox.
Also, I'm using a .sdf database, most other tutorials I've come across seem to use .dbm
Re: [2008] Few Basic Questions
Which database you're using is pretty much irrelevant. ADO.NET code all follows the same pattern. If you're using a different database then you simply change the connection string and, perhaps, the data namespace. Follow the Data Access link in my signature for some ADO.NET code examples. As that thread says, if you're using Access you can just change SqlClient to OleDb. If you're using SQL Server CE then you just switch SqlClient to SqlServerCe.
Re: [2008] Few Basic Questions
I seem to run into trouble at this line:
Code:
Dim connection As New System.Data.SqlServerCe.SqlCeConnection("Microsoft.SQLSERVER.MOBILE.OLEDB.3.0;Data Source=C:\Users\Blake\Documents\Visual Studio 2008\Projects\Ori\Ori\Database1.sdf")
Code as a whole:
Code:
Dim connection As New System.Data.SqlServerCe.SqlCeConnection("Microsoft.SQLSERVER.MOBILE.OLEDB.3.0;Data Source=C:\Users\Blake\Documents\Visual Studio 2008\Projects\Ori\Ori\Database1.sdf")
Dim command As New System.Data.SqlServerCe.SqlCeCommand("SELECT Price, Quest Item, Name FROM Items", connection)
connection.Open()
Dim reader As System.Data.SqlServerCe.SqlCeDataReader = command.ExecuteReader()
While reader.Read()
MessageBox.Show(String.Format("There are {0} {1} of {2} remaining in stock.", _
reader("Quantity"), _
reader("Unit"), _
reader("Name")))
End While
reader.Close()
connection.Close()
Re: [2008] Few Basic Questions
That's not a valid connection string. First up, you're trying to create a SqlCeConnection with a connection string for an OleDbConnection. Secondly, that connection string would not be valid even for an OleDbConnection string because it's not complete. Go to www.connectionstrings.com and read the SSCE page carefully.