elhacker.net cabecera Bienvenido(a), Visitante. Por favor Ingresar o Registrarse
¿Perdiste tu email de activación?.

 

 


Tema destacado: Guía rápida para descarga de herramientas gratuitas de seguridad y desinfección


  Mostrar Mensajes
Páginas: 1 2 3 4 5 [6] 7 8 9 10
51  Programación / Programación Visual Basic / leer datos en archivo secuencial en: 22 Noviembre 2021, 16:41 pm
Hola soy corlo

estoy haciendo una mini aplicacion de guardar datos de factura y leerlos por pantalla, en archivo secuencial.

guardar datos lo hace bien

el problema esta en leer los datos de la factura en pantalla
el archivo es 1.txt y hay lo siguiente:


==============================
           COMPROBANTE DE VENTA
==============================
TICKET Nº: 1                    TIPO : CONTADO
FECHA : 20/11/2021          HORA : 20:30:59
-------------------------------------------------------
R.U.C/C.I : a
CLIENTE   : a
===============================
CANTIDAD  PRODUCTO     PRECIO       SUBTOTAL
===============================
12               r              8          96
3              k              1.5        4,5
===============================
              TOTAL :                           100,50
               -------------------------------------------

          GRACIAS POR SU COMPRA!



me sale todo mezclado


el código que tengo hasta ahora es el siguiente:


Código
  1.  
  2. Option Explicit
  3. Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
  4. Private Const LB_SETTABSTOPS = &H192
  5. Dim I As Integer
  6. Dim orden As Integer 'numero de ticket
  7. Dim fecha As Date 'para leer la fecha
  8. Dim hora As Date 'para leer la hora
  9. Dim contado As String 'para contado
  10. Dim credito As String 'para  credito
  11. Dim cedu1 As String ' para el RUC/C.I
  12. Dim nom1 As String ' para el cliente
  13. 'abajo son datos del list1
  14. Dim cantidad As Integer
  15. Dim producto As String * 12
  16. Dim preciox As String * 8
  17. Dim subtot As Double
  18. 'varible del total
  19. Dim tot As Double
  20. Private Sub Command4_Click()
  21. End
  22. End Sub
  23.  
  24. Private Sub Command5_Click()
  25. 'Nuevo registro
  26. '//recuperar el dato.
  27. Open App.Path & "\Numero1.txt" For Input As #1
  28. Do While Not EOF(1)
  29. Input #1, orden
  30. Loop
  31. Close #1
  32. Txtnum = orden + 1
  33.  
  34.  
  35.  
  36.      List1.Clear
  37.     txtCedula1.Text = ""
  38.     txtNombre1.Text = ""
  39.     total.Text = ""
  40.     txtCedula1.SetFocus
  41.  
  42.  
  43. End Sub
  44.  
  45.  
  46.  
  47. Private Sub Command6_Click()
  48. 'Guardar Factura
  49.  
  50. Dim cantidadtotal As Double
  51. Dim k As Integer
  52.  
  53.  
  54. orden = Txtnum.Text
  55. On Error GoTo salir
  56.  
  57.  
  58.  
  59.  
  60.  
  61.    Open App.Path & "\Numero1.txt" For Append As #1
  62.  
  63.    Print #1, Txtnum
  64.    Close #1
  65.  
  66. Dim bmx As String
  67. bmx = App.Path + "\" + Txtnum + ".txt"
  68.  
  69.  Open bmx For Append As #1
  70.  
  71.  
  72.  Txtnum = orden
  73.  
  74.  
  75.  
  76.    Print #1,
  77.  
  78.    Print #1,
  79.  
  80.    Print #1,
  81.  
  82.  
  83.    Print #1, Tab(1); String(44, "=")
  84.    Print #1, Tab((44 - Len("COMPROBANTE DE VENTA")) \ 2); "COMPROBANTE DE VENTA"
  85.    Print #1, Tab(1); String(44, "=")
  86.  
  87.    If Option1.Value = True Then
  88.        Print #1, Tab(1); "TICKET Nº: " & Txtnum.Text; Tab(44 - Len("TIPO : CONTADO")); "TIPO : CONTADO"
  89.    Else
  90.        Print #1, Tab(1); "TICKET Nº: " & Txtnum.Text; Tab(44 - Len("TIPO : CREDITO")); "TIPO : CREDITO"
  91.    End If
  92.  
  93.    Print #1, Tab(1); "FECHA : " & Date; Tab(44 - Len("HORA : " & Time)); "HORA : " & Time
  94.  
  95.    Print #1, Tab(1); String(44, "-")
  96.  
  97.    Print #1, Tab(1); "R.U.C/C.I : " & txtCedula1.Text
  98.    Print #1, Tab(1); "CLIENTE   : " & txtNombre1.Text
  99.  
  100.    Print #1, Tab(1); String(44, "=")
  101.    Print #1, Tab(1); "CANTIDAD"; Tab(11); "PRODUCTO"; Tab(24); "PRECIO"; Tab(37); "SUBTOTAL"
  102.    Print #1, Tab(1); String(44, "=")
  103.  
  104.  
  105. For k = 0 To List1.ListCount - 1
  106. Print #1, List1.List(k)
  107. Next k
  108.  
  109.  
  110.  
  111.    Print #1, Tab(1); String(44, "=")
  112.    Print #1, Tab(15); "TOTAL : "; Tab(43 - Len(Format(total.Text, "#,##0.00"))); Format(total.Text, "#,##0.00")
  113.    Print #1, Tab(16); "-----------------------------"
  114.  
  115.  
  116.  
  117.    Print #1,
  118.    Print #1, Tab((44 - Len("GRACIAS POR SU COMPRA!")) \ 2); "GRACIAS POR SU COMPRA!"
  119.  
  120.    For I = 1 To 10
  121.        Print #1,
  122.    Next I
  123.  
  124.    Close #1
  125.  
  126.  
  127.  Option1.Value = False
  128. Option2.Value = False
  129.  
  130. txtCedula1.Text = ""
  131. txtNombre1.Text = ""
  132.    List1.Clear
  133. cant.Text = ""
  134. prod.Text = ""
  135. precio.Text = ""
  136. subtotal.Text = ""
  137. total.Text = ""
  138. cant.SetFocus
  139.  
  140.    Exit Sub
  141.  
  142. salir:
  143.  
  144. Dim msgb
  145.  
  146. msgb = MsgBox("Error Nº : [ " & Err.Number & " ]" & " " & Err.Description, vbOKCancel + vbInformation)
  147.  
  148.  
  149. End Sub
  150.  
  151.  
  152.  
  153. Private Sub Command7_Click()
  154. 'Leer Factura
  155. Dim tabs(0 To 3) As Long
  156.    tabs(0) = 20
  157.    tabs(1) = 60
  158.    tabs(2) = 95
  159.    tabs(3) = 138
  160.    ' Set the tabs.
  161.    SendMessage List1.hwnd, LB_SETTABSTOPS, 4, tabs(1)
  162.  
  163.  
  164.  
  165. Dim str As String
  166. Dim thj As String
  167. Dim plo As Boolean
  168. Dim j As Integer
  169. Dim h As Integer
  170. On Error GoTo lo
  171. List1.Clear
  172. thj = App.Path + "\" + Txtnum.Text + ".txt"
  173. If Dir(thj) <> "" Then
  174. Open thj For Input As #1
  175.  
  176. Input #1, orden
  177. Txtnum.Text = orden
  178. Input #1, fecha
  179. Label4.Caption = fecha
  180. Input #1, hora
  181. Label5.Caption = hora
  182. Input #1, contado
  183. Input #1, credito
  184.  
  185. Input #1, cedu1, nom1
  186.  
  187. txtCedula1.Text = cedu1
  188. txtNombre1.Text = nom1
  189.  
  190. While Not EOF(1)
  191.  
  192. Input #1, cantidad, producto, preciox, subtot
  193. cant.Text = cantidad
  194. prod.Text = producto
  195. precio.Text = preciox
  196. subtotal.Text = subtot
  197. List1.AddItem cantidad & vbTab & producto & vbTab & preciox & vbTab & subtot
  198. Wend
  199.  
  200. j = 0
  201.   For h = 0 To List1.ListCount - 1
  202. j = j + Val(Split(List1.List(h), vbTab)(3))
  203. Next h
  204. total.Text = j
  205.  
  206.  
  207.  
  208. Close #1
  209. End If
  210.  
  211. If contado= contado Then
  212. Option1.Value = True
  213. Else
  214.  
  215. If credito = credito Then
  216. Option2.Value = True
  217.  
  218. End If
  219. End If
  220.  
  221.  
  222.  
  223.  
  224.  
  225. Exit Sub
  226. lo:
  227. If Not plo = True Then
  228. MsgBox "La Factura no existe, gracias", vbCritical
  229. End If
  230. End Sub
  231.  
  232. Private Sub Command8_Click()
  233. 'Agregar
  234. Dim h As Integer
  235. Dim j As Double
  236.  
  237. cantidad = cant.Text
  238. producto = prod.Text
  239. preciox = precio.Text
  240. subtot = subtotal.Text
  241.  
  242. List1.AddItem cantidad & vbTab & producto & vbTab & preciox & vbTab & subtot
  243. j = 0
  244.   For h = 0 To List1.ListCount - 1
  245. j = j + Split(List1.List(h), vbTab)(3)
  246. Next h
  247. total.Text = Format(j, "#,##0.00")
  248. cant.Text = ""
  249. prod.Text = ""
  250. precio.Text = ""
  251. subtotal.Text = ""
  252. cant.SetFocus
  253. End Sub
  254.  
  255. Private Sub Form_Load()
  256. Dim tabs(0 To 3) As Long
  257.  
  258.    tabs(0) = 20
  259.    tabs(1) = 123
  260.    tabs(2) = 237
  261.    tabs(3) = 370
  262.  
  263.    SendMessage List1.hwnd, LB_SETTABSTOPS, 4, tabs(1)
  264.  
  265. Option1.Value = False
  266. Option2.Value = False
  267.  
  268. Open App.Path & "\Numero1.txt" For Append As #1
  269. Close #1
  270. Open App.Path & "\Numero1.txt" For Append As #1
  271. Close #1
  272.  
  273. '//recuperar el dato.
  274. Open App.Path & "\Numero1.txt" For Input As #1
  275. Do While Not EOF(1)
  276. Input #1, orden
  277. Loop
  278. Close #1
  279. Txtnum = orden + 1
  280.  
  281. End Sub
  282.  
  283. Private Sub List1_Click()
  284. Text1.Text = Mid(List1.Text, 1, InStr(1, List1.Text, " ") - 1)
  285. Text2.Text = Mid(List1.Text, InStr(1, List1.Text, " ") + 1)
  286. I = List1.ListIndex
  287. End Sub
  288.  
  289.  
  290.  
  291.  
  292.  
  293.  
  294. Private Sub Option1_Click()
  295. Option2.Value = False
  296. End Sub
  297.  
  298. Private Sub Option2_Click()
  299. Option1.Value = False
  300. End Sub
  301.  
  302. Private Sub precio_KeyUp(KeyCode As Integer, Shift As Integer)
  303. subtotal.Text = cant.Text * Val(precio.Text)
  304. End Sub
  305.  
  306. Private Sub Timer1_Timer()
  307. Label4.Caption = Date
  308. Label5.Caption = Format(Time, "hh:mm:ss")
  309. End Sub
  310.  
  311.  
  312.  




Gracias


52  Programación / Programación Visual Basic / Re: eliminar registro en: 11 Noviembre 2021, 00:04 am
Hola  Serapis


Muchas gracias por el codigo

todo correcto lo he adaptado y funciona

 llevaba varios dias con el codigo y no me salia gracias.
53  Programación / Programación Visual Basic / eliminar registro en: 9 Noviembre 2021, 19:14 pm
Hola soy corlo
estoy haciendo una mini aplicacion en añadir datos a los textbox ,  para luego leer los datos con el combo y una opcion para eliminar los datos.

añadir los datos: lo hace bien
leer los datos: lo hace bien
eliminar los datos: elimina el dato en el combo pero no elimina los datos de los textbox
no se que hago mal
paso el codigo que tengo hasta ahora

en un formulario

Código:

Option Explicit


Private Sub Boton_añadir_Click()
totalregistros = totalregistros + 1
If totalregistros > 50 Then
MsgBox "lista completa", 16, "error"
Else
agenda(totalregistros).Nombre = Nom.Text
agenda(totalregistros).apellidos = Ape.Text
agenda(totalregistros).telefono = Tel.Text
agenda(totalregistros).Edad = Val(Edad.Text)

Combo2.AddItem Nom.Text
End If
Nom.SetFocus
End Sub

Private Sub Boton_eliminar_Click()
Dim b As String

b = MsgBox("Eliminar Registro:" + Nom.Text, 3 + 32, "Eliminar")
If b = vbYes Then



If Combo2.ListIndex <> -1 Then




Combo2.RemoveItem (Combo2.ListIndex)



End If

totalregistros = totalregistros - 1

agenda(totalregistros).Nombre = Nom.Text
agenda(totalregistros).apellidos = Ape.Text
agenda(totalregistros).telefono = Tel.Text
agenda(totalregistros).Edad = Val(Edad.Text)





End If
Nom.Text = ""
Ape.Text = ""
Tel.Text = ""
Edad.Text = ""
End Sub

Private Sub Boton_fin_Click()
End
End Sub





Private Sub Botonnuevo_Click()
Nom.Text = ""
Ape.Text = ""
Tel.Text = ""
Edad.Text = ""
Nom.SetFocus

End Sub





Private Sub Combo2_Click()
Dim n As Integer
n = Combo2.ListIndex + 1

Nom.Text = agenda(n).Nombre
Ape.Text = agenda(n).apellidos
Tel.Text = agenda(n).telefono
Edad.Text = Val(agenda(n).Edad)



End Sub

Private Sub Ape_GotFocus()
Ape.SelStart = 0
Ape.SelLength = Len(Ape.Text)
End Sub

Private Sub Edad_GotFocus()
Edad.SelStart = 0
Edad.SelLength = Len(Edad.Text)
End Sub

Private Sub Nom_GotFocus()
Nom.SelStart = 0
Nom.SelLength = Len(Nom.Text)
End Sub
Private Sub Tel_GotFocus()
Tel.SelStart = 0
Tel.SelLength = Len(Tel.Text)
End Sub



Private Sub Form_Load()
totalregistros = 0
End Sub







y en un modulo


Código:

Type registro
Nombre As String * 15
apellidos As String * 25
telefono As String * 15
Edad As String * 3
End Type
Global agenda(1 To 50) As registro
Global totalregistros As Integer









gracias
54  Programación / Programación Visual Basic / descontar valor en list1 de la columna 3 en: 24 Febrero 2021, 00:42 am
Hola soy  corlo


estoy haciendo un pequeño programa necesito descontar el valor que le pongo en el  text3.text
y lo cambie en el valor seleccionado del list1 de la columna 3


en el programa hay los siguientes objetos:

1 list1
1 list2

text1.text
text2.text
text3.text

1 command1 salida
1 command4 ok

la cuestion es que cuando aprieto el command1 la operacion de resta lo hace bien, cuando voy a el command4 no consigo poner el resultado del text3.text  en el list1 del valor seleccionado de la columna 3

aqui esta el codigo que tengo hasta ahora:

Código:


Option Explicit






Private Sub Command1_Click()
'salida ok


 Dim i As Long
Dim arrString() As String
For i = 0 To UBound(arrString)
    List1.AddItem arrString(i)
Next

End Sub

Private Sub Command3_Click()
Unload Me
Form1.Show
End Sub

Private Sub Command4_Click()
'Salida
Dim cantidad As Integer
cantidad = Text1.Text

If Text3.Text > cantidad Then
   MsgBox "No hay suficiente existencia", vbCritical
   Exit Sub
End If

Command1.Visible = True
Text3.Text = Text3.Text - Text1.Text
End Sub

Private Sub Form_Load()
List1.AddItem "p001" & "                     " & "descripciom p001" & "                           " & "42"
List1.AddItem "p002" & "                     " & "descripciom p002" & "                           " & "53"
List1.AddItem "p003" & "                     " & "descripciom p003" & "                           " & "244"
List1.AddItem "p004" & "                     " & "descripciom p004" & "                           " & "75"
Text2.Text = List1.ListCount
Command1.Visible = False
End Sub

Private Sub List1_Click()

    Dim x As Integer
  List2.Clear
   
  List2.AddItem List1.Text

    For x = 0 To List2.ListCount - 1
   
   Text1.Text = Mid(List2.List(x), Len(List2.List(x)) - 2, 3)

   
   Next x
   
   
End Sub






he probado varias formas pero no consigo cambiar el valor del text3 al list1

gracias
55  Programación / Programación Visual Basic / Re: leer user y password en archivos aleatorios en: 7 Enero 2021, 12:52 pm
gracias Serapis por la informacion

con el codigo de EdePC ya me vale, porque hace lo que yo necesito, osea leer text1 y text2
y va al form2, y cuando no existe me dice error registro no existe, cuando creas el user y password lo guarda tal y como lo has escrito, yo tengo a 10 usuarios y no hay problema ninguno.

siempre va bien saber varios temas.

gracias
56  Programación / Programación Visual Basic / Re: leer user y password en archivos aleatorios en: 5 Enero 2021, 18:16 pm
muchas gracias EdePC

justo lo que necesitaba

tema resuelto
57  Programación / Programación Visual Basic / Re: leer user y password en archivos aleatorios en: 5 Enero 2021, 09:48 am
Gracias por responder BlackZeroX (Astaroth)


pero yo tengo el problema en archivo aleatorio no en sql

creo que se entiende el problema que hay
se trata de leer el user y password y que me avise de que vaya al formulario2 cuando existe un usuario y cuando no que vaya a el registro no existe.


gracias
58  Programación / Programación Visual Basic / leer user y password en archivos aleatorios en: 4 Enero 2021, 23:17 pm
Hola soy corlo
tengo el siguiente problema

cuando pongo lo siguiente en el apartado leer user y password

Text1.Text = Access.uname
Text2.Text = Access.passwd

el problema es cuando estoy leyendo el user y password introduzca datos diferentes en el text1.text y el text2.text , y pongo los datos que hay en fichero  siempre me dice bienbenido y va al form2

en cambio cuando quito


Text1.Text = Access.uname
Text2.Text = Access.passwd


siempre me dice El archivo no existe


Aqui pongo el codigo


Código:

Option Explicit
Private Type Authorize
    uname As String * 30
    passwd As String * 30
End Type

Dim Pos As Integer
Dim Cont As Integer
Dim Fnum As Integer






Private Sub Command1_Click()
'Guardar
Dim Access As Authorize


Fnum = FreeFile
Access.uname = Text1.Text
Access.passwd = Text2.Text
Open App.Path & "\members1.dat" For Random As #Fnum Len = Len(Access)
    Cont = LOF(Fnum) / Len(Access)


Pos = Cont + 1
Put Fnum, Pos, Access

MsgBox "Nuevo Usuario Añadido: " & Access.uname & Access.passwd

Close #Fnum
End Sub

Private Sub Command2_Click()
'leer
Dim Access As Authorize
 
    Fnum = FreeFile

Open App.Path & "\members1.dat" For Random As #Fnum Len = Len(Access)
    Cont = LOF(Fnum) / Len(Access)

For Pos = 1 To Cont

   Get #Fnum, Pos, Access
 


   
   
Next
Text1.Text = Access.uname
Text2.Text = Access.passwd

Close #Fnum



   If Text1.Text = "" And Text1.Text <> Access.uname And Text2.Text <> Access.passwd Then
MsgBox "El archivo no existe", vbCritical, "No existe"
Text1.Text = ""
Text2.Text = ""
Exit Sub
End If

If Text1.Text = Access.uname Or Text2.Text = Access.passwd Then
MsgBox "Bienvenido", vbInformation
Form2.Show
Me.Hide
End If











End Sub

Private Sub Command3_Click()
End
End Sub


Private Sub Command4_Click()
Text1.Text = ""
Text2.Text = ""
Text1.SetFocus
End Sub











la pregunta seria:

como solucionar el tema de los avisos en el apartado leer

1. para ir al formulario dos

2. para el registro no existe


Gracias
59  Programación / Programación Visual Basic / Re: imprimir por impresora linea recta mas gruesa en: 15 Noviembre 2020, 22:07 pm
Hola nebire


justo lo que necesitaba, ya lo he probado y funciona perfecto


gracias
60  Programación / Programación Visual Basic / Re: imprimir por impresora linea recta mas gruesa en: 15 Noviembre 2020, 14:01 pm
Hola EDEPC, Gracias por contestar

ya he conseguido que me imprime la linea recta, pero no me hace la linea gruesa


Código:


Printer.Print , "Hola"

DrawWidth = 5
DrawStyle = 2

Line (950, 2950)-(12000, 2950)


Printer.Line (950, 2950)-(12000, 2950)




Printer.EndDoc






Gracias


Páginas: 1 2 3 4 5 [6] 7 8 9 10
WAP2 - Aviso Legal - Powered by SMF 1.1.21 | SMF © 2006-2008, Simple Machines