codigo de mi primer formulario
Código
Imports System Imports System.Data Imports System.IO Imports System.Data.SQLite Public Class Form1 Dim cnn As New SQLiteConnection Public consulta As String Dim frm As Form2 Public ZONA As String Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load cnn = New SQLiteConnection("Data Source=\BACKUP\BD\CLAS_MOBILE.db;Version=3;") Try CrearTablas(cnn) End If Catch ex As Exception MessageBox.Show(ex.Message, "Error") End Try End Sub Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click cnn.Open() If USUARIO.Text = "" Or PASSWORD.Text = "" Then MessageBox.Show("Debe Ingresar Usuario y Contraseña") Else Try consulta = String.Format("SELECT count(USU_USUARIO) as cuenta, USU_ZONA FROM CMB_USUARIO WHERE USU_USUARIO='{0}'", USUARIO.Text) Dim Ada As New SQLiteDataAdapter() Dim Sqlstr As New SQLiteCommand(consulta, cnn) Dim dr As SQLiteDataReader = Sqlstr.ExecuteReader(CommandBehavior.CloseConnection) While dr.Read Dim value As Object = dr.Item("cuenta") Dim value2 As Object = dr.Item("USU_ZONA") ZONA = CStr(value2) ' ESTA ES LA VARIABLE QUE QUIERO PASAR If value = 1 Then ' EN ESTA PARTE UTILIZO UN MODULO PARA CERRAR UN FORM Y ABRIR OTRO Me.Close() Me.Dispose() Me.DialogResult = Windows.Forms.DialogResult.OK Else MessageBox.Show("Usuario o Contraseña Incorrectos...!!!", "Error") End If End While dr.Close() Else MessageBox.Show("No existe base de datos", "Error") End If Catch ex As Exception MessageBox.Show(ex.Message, "Error") End Try End If End Sub Private Sub CrearTablas(ByVal Cnn As SQLiteConnection) Using _Cmd As SQLiteCommand = Cnn.CreateCommand _Cmd.CommandText = "CREATE TABLE CMB_USUARIO (USU_USUARIO VARCHAR (8) NOT NULL,USU_PASS VARCHAR (8) NOT NULL,USU_ZONA VARCHAR (25) NOT NULL)" _Cmd.ExecuteNonQuery() _Cmd.CommandText = "INSERT INTO CMB_USUARIO VALUES('usu01','123456','peru')" _Cmd.ExecuteNonQuery() End Using End Sub End Class
este es el codigo del modulo para cerrar un fomulario y pasar al fomulario 2
Código
Module Module1 Sub Main() Dim vResultado As New Form1 If vResultado.ShowDialog() = DialogResult.OK Then Dim frm As New Form2 frm.ShowDialog() End If End Sub End Module
Este es elcodigo de mi segundo formulario donde se supone que rescato la variable del primer formulario:
Código
Por favor ayuda...
Public Class Form2 Dim zona_frm2 = Form1.ZONA ' AQUI SE SUPONE QUE RESCATO LA VARIABLE Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Me.TextBox1.Text = zona_frm2 ' quiero que lo de la variable lo coloque en este texbox, pero no pasa nada :-S Form1.Close() End Sub Private Sub Label1_ParentChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Label1.ParentChanged Label1.Text = FormatDateTime(Now(), DateFormat.GeneralDate) End Sub Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Me.Hide() Dim frm2 As New Form3 frm2.ShowDialog() End Sub End Class
desde ya muchas gracias.
PD: Gracias a IT que me ayudo hacer el codigo, para la conexion con SQLite