Jump to content


Check out our Community Blogs

Register and join over 40,000 other developers!


Recent Status Updates

View All Updates

Photo
- - - - -

How do I convert the result of a msgbox to a textbox


  • Please log in to reply
7 replies to this topic

#1 tiger2010

tiger2010

    CC Lurker

  • Just Joined
  • Pip
  • 5 posts

Posted 25 August 2010 - 01:09 PM

I am using this code to find out the hard drive size of a computer for a project using VB 2005

Dim cdrive As System.IO.DriveInfo
cdrive = My.Computer.FileSystem.GetDriveInfo("C:\")
MsgBox("Total free space: " & CStr(cdrive.TotalFreeSpace))

How do I convert the output of the msgbox and show the result in a textbox.

Also is there any simple code I can use that can find out system information of a computer, i.,e windows version, amount of ram, type of video card, windows licence key etc and display the results using a textbox instead of a msgbox. Any help would be much appreciated. If anyone has the answer please email me the answer to john_easthill@hotmail.com

Thank you very much
  • 0

#2 PsychoCoder

PsychoCoder

    CC Resident

  • Just Joined
  • PipPipPipPip
  • 89 posts

Posted 25 August 2010 - 03:39 PM

Well we dont want anyone to email it to you, this is a community so let's keep the discussion here in the forums that way when someone comes along with the same question they have something to start with :)

As for your first question. Since you're using .NET it's best practice to stick with the native libraries available to you in the framework. MsgBox and CStr are legacy items left over from the VB6 days. Instead of using MsgBox use the MessageBox Class , instead of CStr use the ToString Method So in VB.NET you would do what you're looking for like this:

Dim cdrive As System.IO.DriveInfo
cdrive = My.Computer.FileSystem.GetDriveInfo("C:\")
TextBox1.Text = String.Format("Total free space: {0}", cdrive.TotalFreeSpace)

As for your 2nd question, you can get system information using WMI
  • 0
SELECT * FROM Users WHERE Clue > 0;
ERROR: 0 results returned
Posted Image

#3 tiger2010

tiger2010

    CC Lurker

  • Just Joined
  • Pip
  • 5 posts

Posted 25 August 2010 - 11:11 PM

thank you for your reply though when I run it ~I get an error - value os type string cannot be converted to system.windows.forms.textbox. I am using vb 2005 if that helps
  • 0

#4 PsychoCoder

PsychoCoder

    CC Resident

  • Just Joined
  • PipPipPipPip
  • 89 posts

Posted 26 August 2010 - 07:00 AM

Show the code you're using now because I'm not getting that with the code I provided
  • 0
SELECT * FROM Users WHERE Clue > 0;
ERROR: 0 results returned
Posted Image

#5 tiger2010

tiger2010

    CC Lurker

  • Just Joined
  • Pip
  • 5 posts

Posted 26 August 2010 - 10:16 PM

thank you for your help it works forgot a bracket, though this only shows in bytes how do i convert this number to show in gigabytes.
  • 0

#6 Vswe

Vswe

    CC Leader

  • Expert Member
  • PipPipPipPipPipPipPip
  • 1989 posts
  • Programming Language:Java, C#, PHP, Python, JavaScript, PL/SQL, Visual Basic .NET, Lua, ActionScript

Posted 27 August 2010 - 02:48 AM

You have to write a function to convert it to gigabytes.
  • 0

#7 Z0MB13

Z0MB13

    CC Lurker

  • Just Joined
  • Pip
  • 1 posts

Posted 01 September 2010 - 07:30 AM

Something like this :)

Function FileSizeFormat(sz)
gb = 1024 ^ 3
Select Case Len(Format(sz / 1024, "#############0"))
    Case 0: t = Format(sz, "##,##0") & " bytes"
    Case 1: t = Format(sz / 1024, "0.00") & " KB"
    Case 2: t = Format(sz / 1024, "#0.0") & " KB"
    Case 3: t = Format(sz / 1024, "##0") & " KB"
    Case 4: t = Format(sz / 1048576, "0.00") & " MB"
    Case 5: t = Format(sz / 1048576, "#0.0") & " MB"
    Case 6: t = Format(sz / 1048576, "##0") & " MB"
    Case 7: t = Format(sz / gb, "0.00") & " GB"
    Case 8: t = Format(sz / gb, "#0.0") & " GB"
    Case 9, 10, 11, 12, 13: t = Format(sz / gb, "###,###,###,##0") & " GB"
    Case Else: t = Format(sz, "#,###,###,###,##0") & " bytes"
End Select
FileSizeFormat = t
End Function

  • 0

#8 blindtrevor

blindtrevor

    CC Lurker

  • Just Joined
  • Pip
  • 6 posts

Posted 17 September 2010 - 05:45 AM

Or:
Function roundBytes(ByVal bytes As String)
        If bytes > 1073741824 Then
            Return Round(bytes / 1073741824, 2) & " GB"
        ElseIf bytes > 1048576 Then
            Return Round(bytes / 1048576, 2) & " MB"
        ElseIf bytes > 1024 Then
            Return Round(bytes / 1024, 2) & " KB"
        Else
            Return bytes & " bytes"
        End If
    End Function

Make sure you add
Imports System.Math
at the top :)

Edited by blindtrevor, 17 September 2010 - 05:46 AM.
Missed a bit!

  • 0




Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download