Visualizzazione dei risultati da 1 a 2 su 2
  1. #1

    [VBA] Convertire una stringa di un TextBox in un numero decimale

    Devo passare un numero da un TextBox (nel formato 1,2) ad una stringa SQL (nel formato 1.2)
    Le impostazioni internazionali prevedono la virgola come separatore decimale, ma in questo caso il server sql si aspetta un numero (non stringa) con punto per separatore.
    Avevo abbozzato questo codice, ma ovviamente non funziona...qualche suggerimento?

    codice:
    Private Sub insert_article_Click()
    'set decimal separator as point
    With Application
    	.DecimalSeparator = "."
    	.ThousandsSeparator = ","
    	.UseSystemSeparators = False
    End With
    Dim number As Double
    Dim word As String
    word = "test"
    number = CDbl(Textnumber.Value) 'if I enter 1,2 ,number will be 1,2
    'I try also this, but number will be 1,2
    'number = Replace(Textnumber.Value, ".", ",")
    strSQL = "INSERT INTO table (col_word, col_number) VALUES ('" & word & "'," & number & ")"
    ...
    End Sub
    Thanks,
    PAOLO

  2. #2
    Sono un pollo!
    La stringa corretta è
    codice:
    Dim number As String
    number = Replace(Textnumber.Value, ",", ".")
    Ora funziona perfettamente,
    CIAOOO
    Thanks,
    PAOLO

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.