Reputation: 587
I'm quite a noob when it comes to classes, subs and that kind of stuff. I'm making a program in VB 2012 that will create a portable version of Minecraft on your USB key.
Here's some code ("port_cr"):
'Get %appdata%
Dim appdata As String = Environ("USERPROFILE") & "\AppData\roaming\.minecraft"
'Get the path
port_mc_getPath.ShowDialog()
Dim save_mc As String = port_mc_getPath.SelectedPath
'Copy everything
My.Computer.FileSystem.CreateDirectory(save_mc & "\Data")
My.Computer.FileSystem.CreateDirectory(save_mc & "\Bin")
My.Computer.FileSystem.CreateDirectory(save_mc & "\Data\.minecraft")
My.Computer.FileSystem.CopyDirectory(appdata, save_mc & "\Data\.minecraft", True)
'OPEN ANOTHER FORM TO CHOOSE THE LAUNCHER YOU WANT TO DOWNLOAD
chooseLauncher.Show()
"chooseLauncher" is a form with some buttons that download the appopriate files to the path specified in the "port_cr" form, which is what I can't figure out how to do. If someone could tell me how to do this simply I'd really appreciate it
Upvotes: 0
Views: 3274
Reputation: 29829
Forms are just fancy types of classes that have some visual behavior / rendering associated with them. In OOP, you can treat them the same way you would treat any class, either custom or native.
Let's take a simple native class in the .NET framework and abstract out from there. How do you pass data to the class DataTable?
'create a new instance of that class
Dim dt as New DataTable
'pass in the name of the table
dt.Name = "AnyName"
I can pass that information to the datatable class because it already has a property that can store the Name info.
Now think about this when you create your own classes. Let's say you have a form which is called ChooseLauncher. Let's give it some properties that it can use internally and be added externally. Perhaps a property called FilePath
Class ChooseLauncher : Inherits Form
Public FilePath As String
End Class
Now when you create the ChooseLauncher class. All you have to do is set the publicly available properties from wherever you created it.
Dim myForm As New ChooseLauncher
myForm.FilePath = "NewValue"
myForm.Show()
Upvotes: 1
Reputation: 43743
Create public properties on the chooseLauncher
form and set them to the values before you show the form. For instance, if the chooseLauncher
form had a public string property called SaveMc
, you could do this:
chooseLauncher.SaveMc = save_mc
chooseLauncher.Show()
Upvotes: 1