-4
Dim form As New Mainuser(TextBox1.Text)

For some reason, even though TextBox1 exists, it still says it's not declared.

Also, in my other part of the code, Mainuser.Show(), it says can not be simplified. Here is my full code if you want to help me with that:

Login.vb:

Dim form As New Mainuser(TextBox1.Text)
If TextBox8.Text = My.Settings.username AndAlso TextBox9.Text = My.Settings.password Then
    MessageBox.Show("You have successfully been logged in!", "Login Successfull")
    Close()
    Mainuser.Show()

Mainuser.vb:

Public Class Mainuser
    Public Sub New(ByVal value As String)

        InitializeComponent()

        Label1.Text = value

    End Sub
    Private Sub PictureBox2_Click(sender As Object, e As EventArgs) Handles PictureBox2.Click
        HTML_Editor.Show()
    End Sub
End Class

Like I said before if this doesn't make any sense I'll comment below what you want.

Oh yeah, here are my error messages:

  1. (BC30451) TextBox1 is not declared. It may be inaccessible due to its protection level.

  2. (BC30469) Reference to a non-shared member requires an object reference.

Bugs
  • 4,491
  • 9
  • 32
  • 41
Zualux
  • 7
  • 1
  • 7
  • Can you show the actual error types and error messages? Also, simply using @Bugs doesn't mean that user will get notified. And if you need to clarify, don't do it in the comments here -- update the question itself. – rory.ap Apr 28 '17 at 11:38
  • 1
    Pretty likely that `TextBox1` exists in a different form than the one you're trying to use it from. It is unclear what relevance the other code you've shown has to anything being asked here. `TextBox1` never appears there. You should be preparing a [MCVE]. Or, better yet, just start reading any of the hundreds of questions here about accessing objects on another form. – Cody Gray - on strike Apr 28 '17 at 11:42
  • 2
    Sigh. I fixed your code formatting once, but I see you've clobbered it by adding in the error message. Please fix the code formatting back. It isn't that hard to indent by 4 spaces. There's even a button on the toolbar that will do it for you, or you can press Ctrl+K. Maybe it would have been smart to read the help before starting to ask questions? – Cody Gray - on strike Apr 28 '17 at 11:43
  • `TextBox1.Text` has to be on the form you want to use it on. Not the form you want to pass the value to. Is that what you're trying to do? – Bugs Apr 28 '17 at 11:49
  • In fact instead of using `TextBox1.Text` _I think_ you want to use `TextBox8.Text`...`Dim form As New Mainuser(TextBox8.Text)` since that is the username you are comparing with – Bugs Apr 28 '17 at 11:52
  • Also please don't ask a new question. Instead you should have edited your other question. – Bugs Apr 28 '17 at 11:54
  • Possible duplicate of [How to pass value from Form1 to Form2](http://stackoverflow.com/questions/42903216/how-to-pass-value-from-form1-to-form2) – Bugs Apr 28 '17 at 12:04
  • @Bugs at least the other guy had declared his TextBox – djv Apr 28 '17 at 14:32
  • @djv yes that certainly helps. – Bugs Apr 28 '17 at 14:34
  • @Bugs it works but my `Mainuser.Show()`, still gives me an error. – Zualux Apr 29 '17 at 01:08
  • @Zualux what is the error? – Bugs Apr 30 '17 at 21:54

1 Answers1

0

This errors can be avoided easily with a module. You can create one by right-clicking on your solution -> Add -> Module.

After that just declare your variables, take this as an example.

Public _stringname As String
Public _decimalname As Decimal
Public _numbername As Integer
Public _doublename As Double

After that, you just call whenever you want it. For example, you have a textbox on form1 that you want to pass the value to form2:

Form1 button click event: _stringname = txtYourTextBox.Text _decimalname = txtYourMaskedTextBox.Text

Form2 Load event: lblYourStringLabel.Text = _stringname lblYourDecimalLabel.Text = _decimal

And so on...

Hope this helps.