Foros del Web » Programación para mayores de 30 ;) » Programación General » Visual Basic clásico »

Visual Basic

Estas en el tema de Visual Basic en el foro de Visual Basic clásico en Foros del Web. Hola amigos. Tengo dos preguntitas 1. Si yo tengo una matriz con 10 textbox, yo asigno cada textbox a un DataSource y DataField en modo ...
  #1 (permalink)  
Antiguo 16/07/2004, 07:22
 
Fecha de Ingreso: noviembre-2003
Ubicación: Paraguay
Mensajes: 382
Antigüedad: 20 años, 5 meses
Puntos: 4
Mensaje Visual Basic

Hola amigos.

Tengo dos preguntitas

1. Si yo tengo una matriz con 10 textbox, yo asigno cada textbox a un DataSource y DataField en modo de diseño. Se puede establecer dinamicamente en tiempo de ejecucion con un for??

yo probe:
For i = 0 To 9
txtNombre(i).DataSource = campo
Next
algo por el estilo, pero me da error jeje

2. Tengo un campo "monto", es numerico y necesito el algoritmo para pasarlo a letras en otro campo.
50.000 -> CINCUENTA MIL

pOR FA denme una manito

gracias
  #2 (permalink)  
Antiguo 16/07/2004, 09:35
 
Fecha de Ingreso: abril-2004
Ubicación: Managua
Mensajes: 150
Antigüedad: 20 años
Puntos: 0
En el primer caso suponiendo que trabajas con control data en el caso de ado y dao es lo mismo unicamente cambia la coneccion

Private Sub Form_Load()
Dim ciclo As Integer

Data1.DatabaseName = "C:\db1.mdb"
Data1.RecordSource = "select * from cli"
Data1.Refresh

For ciclo = 0 To 1
Text1.Item(ciclo).DataField = Data1.Recordset.Fields(ciclo)
Next ciclo
MsgBox Text1.Item(1).Text
End Sub
'////////////////////////////////////////////////////////////////////////////////
En el segundo caso


Primero

Option Explicit

Private Sub Command1_Click()
Dim anuncio As String
Dim var As String
Dim Cantidad As Byte



'PARA ESTABLECER EL CAMBIO DE SEMANTICA
'ENTRE MILLARDOS Y MILES DE MILLONES.
'EN VENEZUELA POR EJEMPLO SE UTILIZA UNO
'U OTRO INDISTINTAMENTE.
If OptiMiles Then
gOpcionMil = True
Else
gOpcionMil = False
End If


'BORRAMOS LAS LABEL DEL FORMULARIO
Label1.Caption = ""
lblFormato.Caption = ""
LblDigitos.Caption = ""

'NO PERMITIR UN CERO EN EL PRIMER DIGITO
'ESTO CONFUNDIRA LA VARIABLE "entero"
If Mid(Text1.Text, 1, 1) = "0" Then
Label1.Caption = "El primer valor de un cifra no puede ser cero. "
Exit Sub
End If

'SI DESEAMOS ACTIVAR/DESACTIVAR EL REDONDEO
'IMPLEMENTEMOS/TAPAMOS ESTA LLAMADA A LA
'FUNCION REDONDEAR Y LIBERAMOS LA VARIABLE var.
If IsNumeric(Text1.Text) Then
If OptiSiRedondeo Then
var = Redondear(Text1.Text, 0)
Else
var = Text1.Text
End If

'NI MENOS NI MÁS, PARA NO PERDER EL TIEMPO.
If Val(var) < -999999999999999# Or Val(var) > 999999999999999# Then
anuncio = MsgBox("La cifra no es traducible.... ", vbCritical)
Exit Sub
End If


Cantidad = Len(Text1.Text)
lblFormato.Caption = Format(var, "Standard") '"###,###,###,###,##0.00")
LblDigitos.Caption = "Cifra de " & Cantidad & " digítos."
Label1.Caption = EnLetras(var) '<=== O "var" redondeada

End If

Text1.SetFocus
End Sub

Private Sub Text1_GotFocus()
Text1.SelStart = 0
Text1.SelLength = Len(Text1.Text)
End Sub

Private Sub Text1_KeyDown(KeyCode As Integer, Shift As Integer)
If KeyCode = 13 Then
Command1_Click
Text1_GotFocus
End If
End Sub
  #3 (permalink)  
Antiguo 16/07/2004, 09:40
 
Fecha de Ingreso: abril-2004
Ubicación: Managua
Mensajes: 150
Antigüedad: 20 años
Puntos: 0
Option Explicit
Global gOpcionMil As Boolean
Public Function Redondear(dblnToR As String, Optional intCntDec As Integer) As String

Dim dblPot As String
Dim dblF As String

If dblnToR < 0 Then dblF = -0.5 Else: dblF = 0.5
dblPot = 10 ^ intCntDec
Redondear = Fix(dblnToR * dblPot * (1 + 1E-16) + dblF) / dblPot

End Function
Public Function EnLetras(numero As String) As String

Dim BandBilion As Boolean
Dim b, paso, cifra As Integer
Dim expresion, entero, deci, flag, valor As String




flag = "N"

'** AQUI REVISAMOS SI EL MONTO TIENE PARTE DECIMAL.
For paso = 1 To Len(numero) 'Determina cuantos caracteres tiene la cadena
If Mid(numero, paso, 1) = "." Or Mid(numero, paso, 1) = "," Then 'dependiendo de la región
flag = "S"
Else
If flag = "N" Then
entero = entero + Mid(numero, paso, 1) 'Extae la parte entera del numero
Else
deci = deci + Mid(numero, paso, 1) 'Extrae la parte decimal del numero
End If
End If
Next paso

'DEFINIMOS VALOR EN LAS VARIABLES
'CIFRA Y VALOR PARA USARLAS COMO
'BANDERAS CONDICIONALES.

cifra = Len(entero)

Select Case cifra
Case Is = 1
valor = "unidad" 'Sin usar
Case Is = 2
valor = "decenas" 'Sin usar
Case Is = 3
valor = "centenas" 'Sin usar
Case Is = 4, 5, 6
valor = "miles" 'Usado
Case Is = 7, 8, 9
valor = "milion" 'Usado
Case Is = 10, 11, 12
valor = "miliardos" 'Usado
Case Is = 13, 14, 15
valor = "biliones" 'Usado
End Select

'*** SI LA CIFRA TIENE VALOR DECIMAL LO ASIGNAMOS AQUI.
If Len(deci) >= 1 Then
If Len(deci) = 1 Then deci = deci & "0"
deci = deci & "/100." 'Antes tenia & "0" "/100."
Else
deci = "00/100."
End If


flag = "N"
If Val(numero) >= -999999999999999# And Val(numero) <= 999999999999999# Then 'si el numero esta dentro de 0 a 999.999.999
For paso = Len(entero) To 1 Step -1
b = Len(entero) - (paso - 1)
Select Case paso
Case 3, 6, 9, 12, 15
Select Case Mid(entero, b, 1)
Case "1"
If Mid(entero, b + 1, 1) = "0" And Mid(entero, b + 2, 1) = "0" Then
expresion = expresion & "cien "
Else
expresion = expresion & "ciento "
End If
Case "2"
expresion = expresion & "doscientos "
Case "3"
expresion = expresion & "trescientos "
Case "4"
expresion = expresion & "cuatrocientos "
Case "5"
expresion = expresion & "quinientos "
Case "6"
expresion = expresion & "seiscientos "
Case "7"
expresion = expresion & "setecientos "
Case "8"
expresion = expresion & "ochocientos "
Case "9"
expresion = expresion & "novecientos "

End Select

Case 2, 5, 8, 11, 14
Select Case Mid(entero, b, 1)
Case "1"
If Mid(entero, b + 1, 1) = "0" Then
flag = "S"
expresion = expresion & "diez "
End If
If Mid(entero, b + 1, 1) = "1" Then
flag = "S"
expresion = expresion & "once "
End If
If Mid(entero, b + 1, 1) = "2" Then
flag = "S"
expresion = expresion & "doce "
End If
If Mid(entero, b + 1, 1) = "3" Then
flag = "S"
expresion = expresion & "trece "
End If
If Mid(entero, b + 1, 1) = "4" Then
flag = "S"
expresion = expresion & "catorce "
End If
If Mid(entero, b + 1, 1) = "5" Then
flag = "S"
expresion = expresion & "quince "
End If
If Mid(entero, b + 1, 1) > "5" Then
flag = "N"
expresion = expresion & "dieci"
End If

Case "2"
If Mid(entero, b + 1, 1) = "0" Then
expresion = expresion & "veinte "
flag = "S"
Else
expresion = expresion & "veinti"
flag = "N"
End If

Case "3"
If Mid(entero, b + 1, 1) = "0" Then
expresion = expresion & "treinta "
flag = "S"
Else
expresion = expresion & "treinta y "
flag = "N"
End If

Case "4"
If Mid(entero, b + 1, 1) = "0" Then
expresion = expresion & "cuarenta "
flag = "S"
Else
expresion = expresion & "cuarenta y "
flag = "N"
End If

Case "5"
If Mid(entero, b + 1, 1) = "0" Then
expresion = expresion & "cincuenta "
flag = "S"
Else
expresion = expresion & "cincuenta y "
flag = "N"
End If

Case "6"
If Mid(entero, b + 1, 1) = "0" Then
expresion = expresion & "sesenta "
flag = "S"
Else
expresion = expresion & "sesenta y "
flag = "N"
End If

Case "7"
If Mid(entero, b + 1, 1) = "0" Then
expresion = expresion & "setenta "
flag = "S"
Else
expresion = expresion & "setenta y "
flag = "N"
End If

Case "8"
If Mid(entero, b + 1, 1) = "0" Then
expresion = expresion & "ochenta "
flag = "S"
Else
expresion = expresion & "ochenta y "
flag = "N"
End If

Case "9"
If Mid(entero, b + 1, 1) = "0" Then
expresion = expresion & "noventa "
flag = "S"
Else
expresion = expresion & "noventa y "
flag = "N"
End If

Case "0"
'expresion = expresion & ""
flag = "N"
End Select
  #4 (permalink)  
Antiguo 16/07/2004, 09:42
 
Fecha de Ingreso: abril-2004
Ubicación: Managua
Mensajes: 150
Antigüedad: 20 años
Puntos: 0
Case 1, 4, 7, 10, 13
Select Case Mid(entero, b, 1)
Case "1"

If flag = "N" Then
If paso = 1 Then
expresion = expresion & "uno "
Else
expresion = expresion & "un "
End If
End If

Case "2"
If flag = "N" Then
expresion = expresion & "dos "
End If

Case "3"
If flag = "N" Then
expresion = expresion & "tres "
End If
Case "4"
If flag = "N" Then
expresion = expresion & "cuatro "
End If
Case "5"
If flag = "N" Then
expresion = expresion & "cinco "
End If
Case "6"
If flag = "N" Then
expresion = expresion & "seis "
End If
Case "7"
If flag = "N" Then
expresion = expresion & "siete "
End If
Case "8"
If flag = "N" Then
expresion = expresion & "ocho "
End If
Case "9"
If flag = "N" Then
expresion = expresion & "nueve "
End If
End Select
End Select

'************************************************* ************************

'********* MILES PARA miles
If paso = 4 And valor = "miles" Then
If Mid(entero, 6, 1) <> "0" Or Mid(entero, 5, 1) <> "0" Or Mid(entero, 4, 1) <> "0" Or _
(Mid(entero, 6, 1) = "0" And Mid(entero, 5, 1) = "0" And Mid(entero, 4, 1) = "0" And _
Len(entero) <= 6) Then
expresion = expresion & "mil "
End If
End If

'********** MILES PARA MILLONES
If paso = 4 And valor = "milion" Then

If cifra = 7 And Val(Mid(entero, 2, 3)) >= 1 Then
expresion = expresion & "mil "
End If


If cifra = 8 And Val(Mid(entero, 3, 3)) >= 1 Then
expresion = expresion & "mil "
End If

If cifra = 9 And Val(Mid(entero, 4, 3)) >= 1 Then
expresion = expresion & "mil "
End If
End If


'********** MILES PARA MILLARDOS
If paso = 4 And valor = "miliardos" Then

If cifra = 10 And Val(Mid(entero, 5, 3)) >= 1 Then
expresion = expresion & "mil "
End If


If cifra = 11 And Val(Mid(entero, 6, 3)) >= 1 Then
expresion = expresion & "mil "
End If

If cifra = 12 And Val(Mid(entero, 7, 3)) >= 1 Then
expresion = expresion & "mil "
End If
End If

'********** MILES PARA BILLONES
If paso = 4 And valor = "biliones" Then

If cifra = 13 And Val(Mid(entero, 8, 3)) >= 1 Then
expresion = expresion & "mil "
End If

If cifra = 14 And Val(Mid(entero, 9, 3)) >= 1 Then
expresion = expresion & "mil "
End If

If cifra = 15 And Val(Mid(entero, 10, 3)) >= 1 Then
expresion = expresion & "mil "
End If
End If

'**********"INICIAMOS CONDICIONES PARA USAR PALABRA MILES DE MILLONES"*****************
Select Case gOpcionMil
Case True 'Desea usar la palabra miles de millones
'Z********[SOLO PARA MILLARDOS] CUANDO MILLONES ES IGUAL A CERO
If paso = 7 And valor = "miliardos" And cifra = 10 _
And Val(Mid(entero, 2, 3)) = 0 Then
expresion = expresion & "millones "
End If


If paso = 7 And valor = "miliardos" And cifra = 11 _
And Val(Mid(entero, 3, 3)) = 0 Then
expresion = expresion & "millones "
End If


If paso = 7 And valor = "miliardos" And cifra = 12 _
And Val(Mid(entero, 4, 3)) = 0 Then
expresion = expresion & "millones "
End If
'Z*****PONER MILLARDOS DE BILLONES ******
If paso = 10 And valor = "biliones" And cifra = 13 _
And Val(Mid(entero, 2, 3)) > 0 Then
expresion = expresion & "mil "
BandBilion = True
End If

If paso = 10 And valor = "biliones" And cifra = 14 _
And Val(Mid(entero, 3, 3)) > 0 Then
expresion = expresion & "mil "
BandBilion = True
End If

If paso = 10 And valor = "biliones" And cifra = 15 _
And Val(Mid(entero, 4, 3)) > 0 Then
expresion = expresion & "mil "
BandBilion = True
End If
  #5 (permalink)  
Antiguo 16/07/2004, 09:43
 
Fecha de Ingreso: abril-2004
Ubicación: Managua
Mensajes: 150
Antigüedad: 20 años
Puntos: 0
'Z******** SOLO PARA BILLONES CUANDO MILLARDOS ES MAS DE CERO
If paso = 7 And valor = "biliones" And cifra = 13 _
And Val(Mid(entero, 5, 3)) = 0 And BandBilion Then
expresion = expresion & "millones "
BandBilion = False
End If

If paso = 7 And valor = "biliones" And cifra = 14 _
And Val(Mid(entero, 6, 3)) = 0 And BandBilion Then
expresion = expresion & "millones "
BandBilion = False
End If

If paso = 7 And valor = "biliones" And cifra = 15 _
And Val(Mid(entero, 7, 3)) = 0 And BandBilion Then
expresion = expresion & "millones "
BandBilion = False
End If

'Z********** SOLO PARA MILLARDOS PRONUNCIADOS EN MILES DE MILLONES.
If paso = 10 And valor = "miliardos" Then
expresion = expresion & "mil "
End If
'**********"TERMINAMOS CONDICIONES PARA USAR PALABRA MILES DE MILLONES"**********


'**********"INICIAMOS CONDICIONES PARA USAR PALABRA MILLARDO(S)"**********
Case Else ' Desea usar la palabra millardos

If paso = 10 And valor = "biliones" And cifra = 13 _
And Val(Mid(entero, 2, 3)) > 0 Then
If Val(Mid(entero, 2, 3)) = 1 Then
expresion = expresion & "millardo "
Else
expresion = expresion & "millardos "
End If
End If
If paso = 10 And valor = "biliones" And cifra = 14 _
And Val(Mid(entero, 3, 3)) > 0 Then
If Val(Mid(entero, 3, 3)) = 1 Then
expresion = expresion & "millardo "
Else
expresion = expresion & "millardos "
End If
End If
If paso = 10 And valor = "biliones" And cifra = 15 _
And Val(Mid(entero, 4, 3)) > 0 Then
If Val(Mid(entero, 4, 3)) = 1 Then
expresion = expresion & "millardo "
Else
expresion = expresion & "millardos "
End If
End If

'********** MILLARDOS

If paso = 10 And valor = "miliardos" Then
If Len(entero) = 10 And Mid(entero, 1, 1) = "1" Then
expresion = expresion & "millardo "
Else
expresion = expresion & "millardos "
End If
End If
'**********"TERMINAMOS CONDICIONES PARA USAR PALABRA MILLARDO(S)"**********
'************************************************* *************************
End Select

'*******[SOLO PARA MILLARDOS] CUANDO MILLONES ES MAS DE CERO

If paso = 7 And valor = "miliardos" And cifra = 10 And _
Val(Mid(entero, 2, 3)) > 0 Then
If Val(Mid(entero, 2, 3)) = 1 Then
expresion = expresion & "millón "
Else
expresion = expresion & "millones "
End If
End If

If paso = 7 And valor = "miliardos" And cifra = 11 _
And Val(Mid(entero, 3, 3)) > 0 Then
If Val(Mid(entero, 3, 3)) = 1 Then
expresion = expresion & "millón "
Else
expresion = expresion & "millones "
End If
End If

If paso = 7 And valor = "miliardos" And cifra = 12 _
And Val(Mid(entero, 4, 3)) > 0 Then
If Val(Mid(entero, 4, 3)) = 1 Then
expresion = expresion & "millón "
Else
expresion = expresion & "millones "
End If
End If

'*************************************************


'******** SOLO BILLONES

If paso = 7 And valor = "biliones" And cifra = 13 _
And Val(Mid(entero, 5, 3)) > 0 Then
If Val(Mid(entero, 5, 3)) = 1 Then
expresion = expresion & "millón "
Else
expresion = expresion & "millones "
End If
End If

If paso = 7 And valor = "biliones" And cifra = 14 _
And Val(Mid(entero, 6, 3)) > 0 Then
If Val(Mid(entero, 6, 3)) = 1 Then
expresion = expresion & "millón "
Else
expresion = expresion & "millones "
End If
End If

If paso = 7 And valor = "biliones" And cifra = 15 _
And Val(Mid(entero, 7, 3)) > 0 Then
If Val(Mid(entero, 7, 3)) = 1 Then
expresion = expresion & "millón "
Else
expresion = expresion & "millones "
End If
End If
'************************************************* ***


'********** SOLO PARA MILLONES
If paso = 7 And valor = "milion" Then
If Len(entero) = 7 And Mid(entero, 1, 1) = "1" Then
expresion = expresion & "millón "
Else
expresion = expresion & "millones "
End If
End If

'******** SOLO PARA BILLONES
If paso = 13 Then
If Len(entero) = 13 And Mid(entero, 1, 1) = "1" Then
expresion = expresion & "billón "
Else
expresion = expresion & "billones "
End If
End If


Next paso




'*** EVALUAR QUE ESCRIBIR
If deci <> "" Then 'SI EL VALOR RESULTANTE ES NEGATIVO CON DECIMAL
If Mid(entero, 1, 1) = "-" Or Mid(entero, 1, 1) = "(" Then
EnLetras = "Menos " & expresion & "con " & deci 'ANTES & "/100"
Else
EnLetras = expresion & "con " & deci 'ANTES & "/100"
End If
Else 'SI EL VALOR RESULTANTE ES NEGATIVO SIN DECIMAL
If Mid(entero, 1, 1) = "-" Or Mid(entero, 1, 1) = "(" Then
EnLetras = "Menos " & expresion
Else
EnLetras = expresion 'si no tiene decimal
End If
End If

If Val(numero) = 0 Then EnLetras = "Monto es igual a cero." 'NO DEBERÍA LLEAGR AQUI
Else 'si el numero a convertir está fuera del rango superior o inferior
EnLetras = "Error en el dato introducido"
End If
End Function
  #6 (permalink)  
Antiguo 16/07/2004, 09:46
 
Fecha de Ingreso: abril-2004
Ubicación: Managua
Mensajes: 150
Antigüedad: 20 años
Puntos: 0
Incluye en el formulario un label llamado lblFormato
un textbox llamado Text1
un boton llamado Command1
un label llamado LblDigitos
  #7 (permalink)  
Antiguo 16/07/2004, 18:30
 
Fecha de Ingreso: junio-2004
Mensajes: 35
Antigüedad: 19 años, 11 meses
Puntos: 0
usar sp

No te compliques la vida en FE, te recomiendo que utilices un SP.
  #8 (permalink)  
Antiguo 22/07/2004, 05:58
 
Fecha de Ingreso: noviembre-2003
Ubicación: Paraguay
Mensajes: 382
Antigüedad: 20 años, 5 meses
Puntos: 4
jejeje. ahora se me complico. No se que es un SP
AYUUUDAAAA
RSILES me dijo que me enviaria un archivo por mail.
[email protected] es mi mail. La verdad que necesito entender como solucionar este problemita
  #9 (permalink)  
Antiguo 22/07/2004, 12:27
 
Fecha de Ingreso: abril-2004
Ubicación: Managua
Mensajes: 150
Antigüedad: 20 años
Puntos: 0
Ya te envie el archivo a tu correo la semana pasada, pero si no lo resiviste te lo vuelvo a envia, ya esta todo hecho solo adaptalo.
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 14:28.