Hi, I'm trying to make a winform (vb, VS2008) application that permits take a file from your hard drive and process it. I've tried to create a empty project with the structure but it appears empty. Until now I've this:
Inicio.Designer.vb:
Inicio.vb:Code:<Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()> _ Partial Class Inicio Inherits System.Windows.Forms.Form 'Form reemplaza a Dispose para limpiar la lista de componentes. <System.Diagnostics.DebuggerNonUserCode()> _ Protected Overrides Sub Dispose(ByVal disposing As Boolean) Try If disposing AndAlso components IsNot Nothing Then components.Dispose() End If Finally MyBase.Dispose(disposing) End Try End Sub 'Requerido por el Diseñador de Windows Forms Private components As System.ComponentModel.IContainer 'NOTA: el Diseñador de Windows Forms necesita el siguiente procedimiento 'Se puede modificar usando el Diseñador de Windows Forms. 'No lo modifique con el editor de código. <System.Diagnostics.DebuggerStepThrough()> _ Private Sub InitializeComponent() Me.lbl_ArchivoAProcesar = New System.Windows.Forms.Label Me.lbl_Modelo = New System.Windows.Forms.Label Me.lbl_FechaFacturacion = New System.Windows.Forms.Label Me.tb_ArchivoAProcesar = New System.Windows.Forms.TextBox Me.bt_ArchivoAProcesar = New System.Windows.Forms.Button Me.cb_Modelo = New System.Windows.Forms.ComboBox Me.tb_FechaFacturacion = New System.Windows.Forms.TextBox Me.bt_Procesar = New System.Windows.Forms.Button Me.SuspendLayout() ' 'lbl_ArchivoAProcesar ' Me.lbl_ArchivoAProcesar.AutoSize = True Me.lbl_ArchivoAProcesar.Location = New System.Drawing.Point(12, 26) Me.lbl_ArchivoAProcesar.Name = "lbl_ArchivoAProcesar" Me.lbl_ArchivoAProcesar.Size = New System.Drawing.Size(100, 13) Me.lbl_ArchivoAProcesar.TabIndex = 0 Me.lbl_ArchivoAProcesar.Text = "Archivo a Procesar:" ' 'lbl_Modelo ' Me.lbl_Modelo.AutoSize = True Me.lbl_Modelo.Location = New System.Drawing.Point(12, 61) Me.lbl_Modelo.Name = "lbl_Modelo" Me.lbl_Modelo.Size = New System.Drawing.Size(45, 13) Me.lbl_Modelo.TabIndex = 0 Me.lbl_Modelo.Text = "Modelo:" ' 'lbl_FechaFacturacion ' Me.lbl_FechaFacturacion.AutoSize = True Me.lbl_FechaFacturacion.Location = New System.Drawing.Point(13, 91) Me.lbl_FechaFacturacion.Name = "lbl_FechaFacturacion" Me.lbl_FechaFacturacion.Size = New System.Drawing.Size(99, 13) Me.lbl_FechaFacturacion.TabIndex = 0 Me.lbl_FechaFacturacion.Text = "Fecha Facturación:" ' 'tb_ArchivoAProcesar ' Me.tb_ArchivoAProcesar.Location = New System.Drawing.Point(131, 23) Me.tb_ArchivoAProcesar.Name = "tb_ArchivoAProcesar" Me.tb_ArchivoAProcesar.ReadOnly = True Me.tb_ArchivoAProcesar.Size = New System.Drawing.Size(437, 20) Me.tb_ArchivoAProcesar.TabIndex = 0 ' 'bt_ArchivoAProcesar ' Me.bt_ArchivoAProcesar.Location = New System.Drawing.Point(586, 22) Me.bt_ArchivoAProcesar.Name = "bt_ArchivoAProcesar" Me.bt_ArchivoAProcesar.Size = New System.Drawing.Size(75, 23) Me.bt_ArchivoAProcesar.TabIndex = 1 Me.bt_ArchivoAProcesar.Text = "Buscar" Me.bt_ArchivoAProcesar.UseVisualStyleBackColor = True ' 'cb_Modelo ' Me.cb_Modelo.FormattingEnabled = True Me.cb_Modelo.Location = New System.Drawing.Point(131, 58) Me.cb_Modelo.Name = "cb_Modelo" Me.cb_Modelo.Size = New System.Drawing.Size(192, 21) Me.cb_Modelo.TabIndex = 2 ' 'tb_FechaFacturacion ' Me.tb_FechaFacturacion.Location = New System.Drawing.Point(131, 88) Me.tb_FechaFacturacion.Name = "tb_FechaFacturacion" Me.tb_FechaFacturacion.Size = New System.Drawing.Size(71, 20) Me.tb_FechaFacturacion.TabIndex = 3 Me.tb_FechaFacturacion.Text = "AAAA_MM" ' 'bt_Procesar ' Me.bt_Procesar.Location = New System.Drawing.Point(15, 128) Me.bt_Procesar.Name = "bt_Procesar" Me.bt_Procesar.Size = New System.Drawing.Size(75, 23) Me.bt_Procesar.TabIndex = 4 Me.bt_Procesar.Text = "Procesar" Me.bt_Procesar.UseVisualStyleBackColor = True ' 'Inicio ' Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 13.0!) Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font Me.ClientSize = New System.Drawing.Size(676, 172) Me.Controls.Add(Me.bt_Procesar) Me.Controls.Add(Me.tb_FechaFacturacion) Me.Controls.Add(Me.cb_Modelo) Me.Controls.Add(Me.bt_ArchivoAProcesar) Me.Controls.Add(Me.tb_ArchivoAProcesar) Me.Controls.Add(Me.lbl_FechaFacturacion) Me.Controls.Add(Me.lbl_Modelo) Me.Controls.Add(Me.lbl_ArchivoAProcesar) Me.Name = "Inicio" Me.Text = "Tratamiento Ficheros Facturación" Me.ResumeLayout(False) Me.PerformLayout() End Sub Friend WithEvents lbl_ArchivoAProcesar As System.Windows.Forms.Label Friend WithEvents lbl_Modelo As System.Windows.Forms.Label Friend WithEvents lbl_FechaFacturacion As System.Windows.Forms.Label Friend WithEvents tb_ArchivoAProcesar As System.Windows.Forms.TextBox Friend WithEvents bt_ArchivoAProcesar As System.Windows.Forms.Button Friend WithEvents cb_Modelo As System.Windows.Forms.ComboBox Friend WithEvents tb_FechaFacturacion As System.Windows.Forms.TextBox Friend WithEvents bt_Procesar As System.Windows.Forms.Button End Class
Doing this I'm obtainning 2 identical errors: "The instruction it's not valid in a namespace"Code:Imports Facturacion Imports System.Windows.Forms Imports System.Drawing Imports System.Data Imports System.Data.SqlClient Imports System.IO Imports System.Net Imports System.Configuration Imports System.Collections.Generic Namespace WindowsFormsApplication1 Public Sub Main() Rellenar_cb_Modelo() End Sub Public Sub Rellenar_cb_Modelo() Try Dim ds As New DataSet Dim cs As ConnectionStringSettings Dim cmd As New SqlCommand() Dim da As New SqlDataAdapter() cs = ConfigurationManager.ConnectionStrings("ODP.SCGC") Dim connString As String = cs.ConnectionString Dim dbConnection As New SqlConnection(connString) cmd = New SqlCommand("SELECT COD_MODELO, TIPO FROM FACT_TXT_MODELOS WHERE COD_ESTADO = @codigo_estado", dbConnection) cmd.Parameters.Add(New SqlParameter("@codigo_estado", 2)) cmd.Parameters("@codigo_estado").Direction = ParameterDirection.Input cmd.CommandType = CommandType.Text da.SelectCommand = cmd da.Fill(ds) Me.cb_Modelo.DataSource = ds.Tables(0) Me.cb_Modelo.DisplayMember = ds.Tables(0).Columns(1).Caption.ToString() Me.cb_Modelo.ValueMember = ds.Tables(0).Columns(0).Caption.ToString() Catch ex As Exception Core.Log4Net.SaveError(ex) End Try End Sub End Namespace
Looking info I've found that I should add something like this:
but here appears my problems again.Code:Imports System.Collections.Generic Imports System.Linq Imports System.Windows.Forms Namespace WindowsFormsApplication1 NotInheritable Class Program Private Sub New() End Sub ''' <summary> ''' Punto de entrada principal para la aplicación. ''' </summary> <STAThread> _ Private Shared Sub Main() Application.EnableVisualStyles() Application.SetCompatibleTextRenderingDefault(False) Application.Run(New Form1()) End Sub End Class End Namespace
If I make this I'm obtainning the message: "Me it's only valid in a instance method". And if I take out the Shared I obtain 2 different errors:Code:Namespace WindowsFormsApplication1 NotInheritable Class Program Private Sub New() End Sub ''' <summary> ''' Punto de entrada principal para la aplicación. ''' </summary> <STAThread()> _ Private Shared Sub Main() Application.EnableVisualStyles() Application.SetCompatibleTextRenderingDefault(False) Application.Run(New Inicio()) Rellenar_cb_Modelo() End Sub Public Shared Sub Rellenar_cb_Modelo() End Sub End Class End Namespace
1. Cannot refer to an instance member of a class from within a shared method or shared member initializer without an explicit instance of the class.
2. cb_Modelo it's not a "FicheroFacturacion.WindowsFormsApplication1.Program" member.
Any idea how to solve this? and more important, why? if it's not possible any idea will be appreciated. Thanks in advance.


Reply With Quote
Bookmarks