[Gambas-user] (no subject)

Jaap Cramer jaap_cramer at ...67...
Mon Jan 21 16:42:22 CET 2008


Hi Pablo

I tried to understand your code, but because many text and variablenames are in spanish (i think) I cant 

When I use multiple forms, I usualy make a Module (MainMOD) as StartupClass.
In Module I call the form, like:

dim fM as new FormMain
fM.showModal

When I am in a Form, I can call all my public variables by MainMOD.varName, and call even another form , and controls thereon like MainMOD.fM.TextBox1.Text

I you want to send data form 1 form to another I suggest you do it like

PUBLIC SUB tbvData_DblClick()
  MODULEName.fM.ControlName.Text = tbvData.Current.Text
  ...
  ME.close
END

IMPORTANT: I believe to do this u need to set in the project/properties/options the option 'form controls as public' to true
Hope it helps!

Jaap


----------------------------------------
> From: piramix at ...178...
> To: gambas-user at lists.sourceforge.net
> Date: Mon, 21 Jan 2008 10:05:55 -0500
> Subject: [Gambas-user] (no subject)
> 
> Hi everybody and thanks in advance. Every help will be appreciated.
> Mi question must be simple but I've been trying to find a solution for my problem for about a week and still haven't found it.
> Here's the deal.
> I have a basic program wich stores data in a mysql database, using several tables wich a form that searches in a every table in particular; I'd like use the same form for every search. In that form I use a ListView control to show data to the user, so, when the user doubleclicks on a field of the listview I need the form to close itself and send the data (only one field) to the form wich made the call. To avoid problems I'm using the same names for control to every form. How should I do to make the search form to do that?
> I do not know if I can attach files so here I post the code I already made:
> 
> For the Locali form:
> 
> ' Gambas class file
> 
> PRIVATE $hConn AS Connection
> 
> PUBLIC SUB Form_Open()
>  $hConn = NEW Connection
>  GoConnect
> END
> 
> PUBLIC SUB GoConnect()
>  TRY $hConn.Close
>    WITH $hConn
>      .Type = "mysql"
>      .Host = "localhost"
>      .Login = "root"
>      .Password = ""
>      .Name = ""
>    END WITH
>    $hConn.Name = "LABORA"
>    $hConn.Open
>  CATCH
>    Message.Error(Error.Text)
> END
> 
> PUBLIC SUB Form_Close()
> END
> 
> PUBLIC SUB BotGuarda_Click()
>  DIM AgregaDatos AS Result
> IF Codigo.Text = "" OR Nombre.Text = "" OR Provin.Text = "" THEN
>  Message.Error("Datos insuficientes. No se puede guardar el registro.")
> ELSE
>  INC Application.Busy
>  $hConn.Begin
>  AgregaDatos = $hConn.Create("LOCALI")
>  AgregaDatos!CODIGO = Codigo.Text
>  AgregaDatos!NOMBRE = Nombre.Text
>  AgregaDatos!PROVIN = Provin.Text
>  AgregaDatos.Update
>  $hConn.Commit
>  DEC Application.Busy
>  Message.Info("El registro se guardó correctamente.")
>  BorrForm
> CATCH
>  $hConn.Rollback
>  Message.Error(DConv(Error.Text))
> ENDIF
> END
> 
> PUBLIC SUB BotNuevo_Click()
>  BorrForm
> END
> 
> PUBLIC SUB BotCodigo_Click()
>  DIM rDatos AS Result
>  DIM hBusqueda AS Buscar
>  rDatos = $hConn.Exec("SELECT * FROM LOCALI ORDER BY NOMBRE")
>  hBusqueda = NEW Buscar($hConn, rDatos)
>  hBusqueda.Show
>  Codigo.Text = Comun.MiNombre
> END
> 
> PUBLIC SUB BotProvin_Click()
>  DIM rDatos AS Result
>  DIM hBusqueda AS Buscar
>  rDatos = $hConn.Exec("SELECT * FROM PROVIN ORDER BY NOMBRE")
>  hBusqueda = NEW Buscar($hConn, rDatos)
>  hBusqueda.Show END
> 
> PUBLIC SUB Codigo_LostFocus()
>  ActuForm
> END
> 
> PUBLIC SUB ActuForm()
>  DIM rDatos AS Result
>  IF Codigo.text <> "" THEN
>    rDatos = $hConn.Exec("SELECT * FROM LOCALI WHERE CODIGO ='" & Codigo.Text & "'")
>    IF rDatos.Available THEN
>      Nombre.Text = rDatos!NOMBRE
>      Provin.Text = rDatos!PROVIN
>    ELSE
>    ENDIF
>  ENDIF
> END
> 
> 
> PUBLIC SUB BorrForm()
>  Codigo.Text = ""
>  Nombre.Text = ""
>  Provin.Text = ""
>  TextProvin.Text = ""
> END
> 
> PUBLIC SUB Provin_LostFocus()
>  DIM rDatos AS Result
>  rDatos = $hConn.Exec("SELECT NOMBRE FROM PROVIN WHERE CODIGO ='" & Provin.Text & "'")
>  IF rDatos.Available THEN
>    TextProvin.Text = rDatos!NOMBRE
>  ELSE
>    TextProvin.Text = ""
>  ENDIF
> END
> 
> 
> ###########
> 
> 
> For the search form:
> 
> ' Gambas class file
> 
> PRIVATE $hConn AS Connection
> PRIVATE $rDatos AS Result
> fine AS Boolean
> cur AS Integer
> 
> PUBLIC SUB _new(hConn AS Connection, rDatos AS Result)
>  $hConn = hConn
>  $rDatos = rDatos
>  ReadData
>  ME.Move(Int(Rnd(Desktop.W - ME.W)), Int(Rnd(Desktop.H - ME.H)))
> END
> 
> PRIVATE SUB ReadData()
>  DIM hField AS ResultField
>  DIM iInd AS Integer
>  INC Application.Busy
>  tbvData.Rows.Count = 0
>  tbvData.Columns.Count = $rDatos.Fields.Count
>  FOR EACH hField IN $rDatos.Fields
>    WITH hField
>      tbvData.Columns[iInd].Text = .Name
>      tbvData.Columns[iInd].Width = WidthFromType(tbvData, .Type, .Length, .Name)
>    END WITH
>    INC iInd
>  NEXT
>  IF $rDatos.Count = -1 THEN
>    tbvData.Rows.Count = rowcount()
>  ELSE
>  tbvData.Rows.Count = $rDatos.Count
>  ENDIF
> FINALLY
>  DEC Application.Busy
> CATCH
>  Message.Error("No se puede efectuar la consulta solicitada." & "\n\n" & DConv(Error.Text))
> END
> 
> PUBLIC SUB tbvData_Data(Row AS Integer, Column AS Integer)
>  $rDatos.MoveTo(Row)
>  tbvData.Data.Text = Str($rDatos[tbvData.Columns[Column].Text])
>  tbvData.Data.Background = Color.RGB(((Row MOD 2) + 1) * 255, ((Row MOD 2) + 1) * 255, ((Row MOD 2) + 1) * 225)
>  tbvData.Data.Foreground = Color.Black
> END
> 
> PUBLIC SUB Form_Resize()
>  tbvData.Resize(ME.ClientW, ME.ClientH)
> END
> 
> PRIVATE FUNCTION WidthFromType(hCtrl AS control, iType AS Integer, iLength AS Integer, sTitle AS String) AS Integer
>  DIM iWidth AS Integer
>  SELECT CASE iType
>    CASE gb.Boolean
>      iWidth = hCtrl.Font.Width(Str(FALSE)) + 32
>    CASE gb.Integer
>      iWidth = hCtrl.Font.Width("1234567890") + 16
>    CASE gb.Long
>      iWidth = hCtrl.Font.Width("12345678901234567890") + 16
>    CASE gb.Float
>      iWidth = hCtrl.Font.Width(CStr(Pi) & "E+999") + 16
>    CASE gb.Date
>      iWidth = hCtrl.Font.Width(Str(Now)) + 16
>    CASE gb.String
>      IF iLength = 0 THEN iLength = 255
>      iLength = Min(32, iLength)
>      iWidth = hCtrl.Font.Width("X") * iLength + 16
>  END SELECT
>  iWidth = Max(iWidth, hCtrl.Font.Width(sTitle) + 8)
>  RETURN iWidth
> END
> 
> PRIVATE FUNCTION rowcount() AS Integer
>  DIM rows AS Integer
>  rows = 0
>  DO
>    $rDatos.MoveTo(rows)
>   INC rows
>  LOOP
> CATCH
>  RETURN rows
> END
> 
> PUBLIC SUB tbvData_DblClick()
>  Comun.MiNombre = tbvData.Current.Text
>  Locali.Codigo.Text = Comun.MiNombre      # I'm using this variable to pass the name to the parent form but it doesn't work as I intented to
>  Locali.ActuForm    # This is a sub wich refresh data at the parent form
>  ME.Close
> END
> 
> 
> 
> Greetings.
> Pablo.
> 
> 
> -- 
> Want an e-mail address like mine?
> Get a free e-mail account today at www.mail.com!
> 
> 
> -------------------------------------------------------------------------
> This SF.net email is sponsored by: Microsoft
> Defy all challenges. Microsoft(R) Visual Studio 2008.
> http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
> _______________________________________________
> Gambas-user mailing list
> Gambas-user at lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/gambas-user

_________________________________________________________________
Probeer Live Search: de zoekmachine van de makers van MSN! 
http://www.live.com/?searchOnly=true



More information about the User mailing list