VB Questions

Post here about scripting and programming for HaloPC (audio, network, ai, etc.)
User avatar
Patrickh




Wordewatician 500

Posts: 1173
Joined: Wed Mar 14, 2007 4:53 pm

VB Questions

Post by Patrickh »

I'm new to making applications, and I need to know how to (in VB) make it so when you click your button, it opens a new form that you can add things to. Help is always appreciated, thanks.
Last edited by Patrickh on Sat Jun 30, 2007 10:21 pm, edited 1 time in total.
Image
conure says: or i could jsut incase my shoes in papar mache, followed by my dog
|||Lethargy||| Mr. Mohawk|||
|||feel free to contact me via PMs, AIM, MSNM, or Xfire if you have any questions|||
stephen10101





Posts: 140
Joined: Sat Jul 29, 2006 9:11 pm
Location: Klein, TX

Post by stephen10101 »

In VB 6 you go to project and then add form, then you put a command button and the code for it is (if you named the new form form2, if not replace form2 with what you named it.)

Code: Select all

form2.visible = true
In VB.net you go to project and then add windows form and put a command button and the code is

Code: Select all

YourForm'sNameHere.show()
I hope that was helpful.
User avatar
Altimit01




Connoisseur Snitch! Literarian 500

Posts: 947
Joined: Sun Jun 04, 2006 12:10 pm

Post by Altimit01 »

In another basic dialect, you can also add windows in code if you want to have multiple instances of a form. (Which might be useful for what you need to do.) It should work in VB.

First make and design a new form in your IDE like stephen10101 said. Then when you want to add that window during runtime do something like this:

Code: Select all

dim w as new custom_form
w.show
Image
Download Eschaton: Halomods | Filefront | Mediafire
User avatar
Dagger13





Posts: 370
Joined: Wed Nov 22, 2006 12:37 pm

Post by Dagger13 »

for vb 2005 press this button

Image
Image(An Old one.)
User avatar
LuxuriousMeat





Posts: 824
Joined: Thu Nov 03, 2005 6:43 pm
Location: zzzzzzzzzzzzzzzz
Contact:

Post by LuxuriousMeat »

Dagger13 wrote:for vb 2005 press this button

Image
He wants to open a form he already made, not add a new form to his project.
Image
User avatar
Dagger13





Posts: 370
Joined: Wed Nov 22, 2006 12:37 pm

Post by Dagger13 »

o ok yeah then all u do is type

Code: Select all

form2(or what ever its name is).show()
Image(An Old one.)
User avatar
Patrickh




Wordewatician 500

Posts: 1173
Joined: Wed Mar 14, 2007 4:53 pm

Post by Patrickh »

Wow! Thank you guys so much. I can do all sorts of things I was just really tired of jamming them all into one form. Now the possibilities are endless!
Thanks again.
Image
conure says: or i could jsut incase my shoes in papar mache, followed by my dog
|||Lethargy||| Mr. Mohawk|||
|||feel free to contact me via PMs, AIM, MSNM, or Xfire if you have any questions|||
PlasmaGhost





Posts: 149
Joined: Wed Oct 05, 2005 12:23 pm

Post by PlasmaGhost »

You should give C# a chance :wink:
User avatar
Patrickh




Wordewatician 500

Posts: 1173
Joined: Wed Mar 14, 2007 4:53 pm

Post by Patrickh »

yeah, the reason I'm doing VB is because I started off using Locke's tutorials. :)
I have another problem, I'm not sure why this doesn't work.
My main form is called frmExplorer2. Then I have another form (form4) that contains a textbox (TextBox1) and a button (cmdname)
I tried to make it so that if you type some thing in the box, then hit the button, it sets the title of the main form to whatever's in the box. It worked when I put the box and button in the main form, but not when they are in the new window (it just does nothing). Anyway, here's what I wrote:

Code: Select all

Public Class Form4
    Private Sub cmdname_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
        frmExplorer2.Text = "" & TextBox1.Text
    End Sub

End Class
no build errors, but it doesn't work...
Image
conure says: or i could jsut incase my shoes in papar mache, followed by my dog
|||Lethargy||| Mr. Mohawk|||
|||feel free to contact me via PMs, AIM, MSNM, or Xfire if you have any questions|||
User avatar
Dagger13





Posts: 370
Joined: Wed Nov 22, 2006 12:37 pm

Post by Dagger13 »

because you wrote frmexplorer2 and not form2 or in your case form4

Code: Select all

Public Class Form4
    Private Sub cmdname_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
        frmExplorer2.Text = "" & TextBox1.Text
    End Sub

End Class
it should be like this

Code: Select all

Public Class Form4
    Private Sub cmdname_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
       form4.Text = "" & TextBox1.Text
    End Sub

End Class
and the reason u have a exploer is beacause you picked explorer instead of windows form
Image(An Old one.)
User avatar
Altimit01




Connoisseur Snitch! Literarian 500

Posts: 947
Joined: Sun Jun 04, 2006 12:10 pm

Post by Altimit01 »

Patrickh wrote:My main form is called frmExplorer2. Then I have another form (form4) that contains a textbox (TextBox1) and a button (cmdname)
I tried to make it so that if you type some thing in the box (in form4), then hit the button (also in form4), it sets the title of the main form (frmExplorer2) to whatever's in the box...
You misunderstand what the problem is. And I can't figure out why that wouldn't work. You might need to refresh the form to make the change visible.

Code: Select all

Public Class Form4 
    Private Sub cmdname_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) 
        frmExplorer2.Text = "" & TextBox1.Text 
		frmExplorer2.Refresh
    End Sub 

End Class
Image
Download Eschaton: Halomods | Filefront | Mediafire
User avatar
Patrickh




Wordewatician 500

Posts: 1173
Joined: Wed Mar 14, 2007 4:53 pm

Post by Patrickh »

Okay, I erased it all and typed it out again and it worked. Dagger, yours works for changing the name of form4, except you have to change form4 in the third line to 'Me'.
I was trying to change the name of a different form via this form. Here's what it looks like:

Code: Select all

Public Class Form4
    Private Sub cmdname_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdname.Click
        frmExplorer2.Text = "" & TextBox1.Text

    End Sub
End Class
Image
conure says: or i could jsut incase my shoes in papar mache, followed by my dog
|||Lethargy||| Mr. Mohawk|||
|||feel free to contact me via PMs, AIM, MSNM, or Xfire if you have any questions|||
User avatar
Dagger13





Posts: 370
Joined: Wed Nov 22, 2006 12:37 pm

Post by Dagger13 »

Code: Select all

Public Class Form4 
    Private Sub cmdname_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) 
        frmExplorer2.Text = "" & TextBox1.Text 
		frmExplorer2.Refresh
    End Sub 

End Class
no u dont have to refresh it and yes i forgot u do have to put "me.show"
and make sure you have the form that u want to change the name is open
Image(An Old one.)
User avatar
Patrickh




Wordewatician 500

Posts: 1173
Joined: Wed Mar 14, 2007 4:53 pm

Post by Patrickh »

Would anybody mind if I just renamed this topic to 'VB questions' and just posted any problems/questions here rather than flooding the section with new topics?
Image
conure says: or i could jsut incase my shoes in papar mache, followed by my dog
|||Lethargy||| Mr. Mohawk|||
|||feel free to contact me via PMs, AIM, MSNM, or Xfire if you have any questions|||
User avatar
Dagger13





Posts: 370
Joined: Wed Nov 22, 2006 12:37 pm

Post by Dagger13 »

i wouldnt mind and i would be happy to help
Image(An Old one.)
User avatar
Patrickh




Wordewatician 500

Posts: 1173
Joined: Wed Mar 14, 2007 4:53 pm

Post by Patrickh »

Ok, new problem. I made a program that opens .txts, edits them and then can save them somewhere. So I decided to make another one but for images. I got it so that when you hit File>Open it opens a Open Folder Dialogue, you browse for an image, hit open, and the image appears in a picbox, with the location in a textbox. no issues so far. However, I can't get it to save :? . I've tried several methods with no luck. I need the code so that when you hit a button, lets say 'cmdSave', a Save File Dialog opens, and you can save your image (as a JPEG, I can figure out the rest). Call the Box whatever, I can always edit it, but I need a working code to study for future use. Thanks a lot to whoever helps me.
EDIT: Actually if you can only save as bmp that's fine too. And keep in mind I started programming like 2 or 3 days ago.
Image
conure says: or i could jsut incase my shoes in papar mache, followed by my dog
|||Lethargy||| Mr. Mohawk|||
|||feel free to contact me via PMs, AIM, MSNM, or Xfire if you have any questions|||
OwnZ joO




Articulatist 500

Posts: 980
Joined: Thu Nov 10, 2005 4:24 pm

Post by OwnZ joO »

Dagger13 wrote:

Code: Select all

Public Class Form4 
    Private Sub cmdname_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) 
        [b]frmExplorer2.Text = "" & TextBox1.Text [/b]
		frmExplorer2.Refresh
    End Sub 

End Class
no u dont have to refresh it and yes i forgot u do have to put "me.show"
and make sure you have the form that u want to change the name is open
Jw why you concant empty string and TextBox1.Text, you can just put TextBox1.Text, and if you're trying to add what's in TextBox1 to the end of frmExplorer2.Text you should put &= i think(I forgot most of what I learned in VB.net). That's where I started out too, but I like C# better.
User avatar
Prey




Connoisseur Snitch! Pyre Articulatist 500

Posts: 1026
Joined: Wed Dec 27, 2006 6:49 am
Location: UK
Contact:

Post by Prey »

Heres the C# for saving the image of a picturebox, should only be marginally different in VB

Code: Select all

//let p be the picturebox
p.Image.Save("filename", System.Drawing.Imaging.ImageFormat.Bmp);
Halo 2 Prophet - Skin with ease with the simple 3D point and click interface.
Halo 3 Research Thread - Contribute to the research into Halo 3.
User avatar
Patrickh




Wordewatician 500

Posts: 1173
Joined: Wed Mar 14, 2007 4:53 pm

Post by Patrickh »

I think it's much different in VB, I'll tinker with that though.
Image
conure says: or i could jsut incase my shoes in papar mache, followed by my dog
|||Lethargy||| Mr. Mohawk|||
|||feel free to contact me via PMs, AIM, MSNM, or Xfire if you have any questions|||
User avatar
LuxuriousMeat





Posts: 824
Joined: Thu Nov 03, 2005 6:43 pm
Location: zzzzzzzzzzzzzzzz
Contact:

Post by LuxuriousMeat »

Patrickh wrote:I think it's much different in VB, I'll tinker with that though.
Nope its the exact same way...

Code: Select all

Public Class Form1

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        PictureBox1.Image.Save("filename", System.Drawing.Imaging.ImageFormat.Jpeg)
    End Sub

End Class

Image
Post Reply