Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. VB 6.0 printf-like string function?

VB 6.0 printf-like string function?

Scheduled Pinned Locked Moved Visual Basic
csharpc++databasetutorial
4 Posts 3 Posters 1 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    Derek Price
    wrote on last edited by
    #1

    I am a C++ programmer just starting work on a VB program (for the first time), and could find a string format similar to printf or CString::Format(). Does VB 6.0 (not VB.NET) support this? If not, is the only other way concatenating strings? For example (VC++ CString::Format()): strTemp.Format( "Visual Basic %d", 6 ); This is a simple example, but if I had a lengthy SQL statement, this would be handy... Thanks in advance! Derek

    P 1 Reply Last reply
    0
    • D Derek Price

      I am a C++ programmer just starting work on a VB program (for the first time), and could find a string format similar to printf or CString::Format(). Does VB 6.0 (not VB.NET) support this? If not, is the only other way concatenating strings? For example (VC++ CString::Format()): strTemp.Format( "Visual Basic %d", 6 ); This is a simple example, but if I had a lengthy SQL statement, this would be handy... Thanks in advance! Derek

      P Offline
      P Offline
      pnpfriend
      wrote on last edited by
      #2

      I'm beginner in VB too.. that's what I found in MFC. Hope it is useful. Dim MyTime, MyDate, MyStr MyTime = #17:04:23# MyDate = #January 27, 1993# ' Returns current system time in the system-defined long time format. MyStr = Format(Time, "Long Time") ' Returns current system date in the system-defined long date format. MyStr = Format(Date, "Long Date") MyStr = Format(MyTime, "h:m:s") ' Returns "17:4:23". MyStr = Format(MyTime, "hh:mm:ss AMPM") ' Returns "05:04:23 PM". MyStr = Format(MyDate, "dddd, mmm d yyyy") ' Returns "Wednesday, ' Jan 27 1993". ' If format is not supplied, a string is returned. MyStr = Format(23) ' Returns "23". ' User-defined formats. MyStr = Format(5459.4, "##,##0.00") ' Returns "5,459.40". MyStr = Format(334.9, "###0.00") ' Returns "334.90". MyStr = Format(5, "0.00%") ' Returns "500.00%". MyStr = Format("HELLO", "<") ' Returns "hello". MyStr = Format("This is it", ">") ' Returns "THIS IS IT".

      D 1 Reply Last reply
      0
      • P pnpfriend

        I'm beginner in VB too.. that's what I found in MFC. Hope it is useful. Dim MyTime, MyDate, MyStr MyTime = #17:04:23# MyDate = #January 27, 1993# ' Returns current system time in the system-defined long time format. MyStr = Format(Time, "Long Time") ' Returns current system date in the system-defined long date format. MyStr = Format(Date, "Long Date") MyStr = Format(MyTime, "h:m:s") ' Returns "17:4:23". MyStr = Format(MyTime, "hh:mm:ss AMPM") ' Returns "05:04:23 PM". MyStr = Format(MyDate, "dddd, mmm d yyyy") ' Returns "Wednesday, ' Jan 27 1993". ' If format is not supplied, a string is returned. MyStr = Format(23) ' Returns "23". ' User-defined formats. MyStr = Format(5459.4, "##,##0.00") ' Returns "5,459.40". MyStr = Format(334.9, "###0.00") ' Returns "334.90". MyStr = Format(5, "0.00%") ' Returns "500.00%". MyStr = Format("HELLO", "<") ' Returns "hello". MyStr = Format("This is it", ">") ' Returns "THIS IS IT".

        D Offline
        D Offline
        Derek Price
        wrote on last edited by
        #3

        Thanks - unfortunately I was looking for something like: ' Note: Contrived example... Dim fmt As String Dim sql As String 'Imaginary Format Function fmt = "SELECT FirstName from Employee WHERE Zip=%d and AreaCode=%d" sql = Format(fmt, 04401, 207) Does this imaginary function exist natively in VB 6.0 somewhere?

        M 1 Reply Last reply
        0
        • D Derek Price

          Thanks - unfortunately I was looking for something like: ' Note: Contrived example... Dim fmt As String Dim sql As String 'Imaginary Format Function fmt = "SELECT FirstName from Employee WHERE Zip=%d and AreaCode=%d" sql = Format(fmt, 04401, 207) Does this imaginary function exist natively in VB 6.0 somewhere?

          M Offline
          M Offline
          mixahlos
          wrote on last edited by
          #4

          I work c++ and vb to and i can tell you that those languages have nothing common. For example with the "printf" function you display something on the screen In vb you need to crate a label or text for example and the assign the value you want to your object. eg. 'Declare your variables Dim fmt As String Dim sql As String Dim InputStr As String ' %d is an input from the user right? So here you have to do this using a text box. 'when the user types the value he wants in the text box you get it and work with it ' eg Let say user gives the value "18542" for are code in the text box InputStr = text1.text ' Now the InputStr Variable has the value "18542" fmt = "Select Firstname from Employee where zip = " & InputStr ' This means that the statement is Select Firstname from Employee where zip = 18542 ' Those results don't expect to get them anywhere in the screen ' Create a Label or text (label for example and connect it to your data control 'Refresh your data control after assigning your new SQL Statement and you will get the result in your label I hope this will help you Mike Economou

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups