PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197

PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197

PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197

PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197

PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197
Import-VBForums
Results 1 to 3 of 3

Thread: Import

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Dec 2011
    Posts
    669

    Import

    Hi


    What the below line does
    Imports VB6 = Microsoft.VisualBasic

    Thanks

  2. #2
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    102,754

    Re: Import

    An Import directive allows you to use specify that a type qualification exists throughout the file or project. For instance, if you wanted to use a SqlConnection in code, you'd have to do this if you had no Imports:
    vb.net Code:
    1. Dim connection As New System.Data.SqlClient.SqlConnection("connection string here")
    Because most VB projects have the System.Data namespace imported by default, you can do this right off the bat:
    vb.net Code:
    1. Dim connection As New SqlClient.SqlConnection("connection string here")
    Because of the Import, the compiler will look in the System.Data namespace to see if the SqlClient.SqlConnection type exists, which is does. If you import the System.Data.SqlClient namespace then you don;t need to qualify the type at all:
    vb.net Code:
    1. Dim connection As New SqlConnection("connection string here")
    The Import that you have shown doesn't just import a namespace but also specifies an alias for it. That means that anywhere you would normally use the Microsoft.VisualBasic namespace in code to qualify a type or member, you can now use VB6 instead, e.g. instead of:
    vb.net Code:
    1. Microsoft.VisualBasic.MsgBox("Hello World")
    you can use:
    vb.net Code:
    1. VB6.MsgBox("Hello World")
    The thing is, the Microsoft.VisualBasic namespace is already imported by default anyway, so there's no need for any qualification in such cases. If you have copied code form somewhere, it was probably done so that it would be clear when a Runtime function (which are basically holdovers from VB6) was being used.

  3. #3
    Hyperactive Member
    Join Date
    Jun 2018
    Posts
    412

    Re: Import

    Jag,

    That old vb6 code you posted in several quesitons has no equal in .net. The twipstopixel function is vb6 code. It does not exist in vb.net.

    Here is a function you can try that you may be able to use to replace your old vb6 code in .net. You will have to test, debug, and improve it.

    The example will return the dpix for your current monitor because that is what twips was for. My monitor is 96 dpi as shown in the example image.

    However you will be better off learning what you are doing and rewriting your old vb6 code for .net as jmc and others have said and etc.


    Name:  a.png
Views: 32
Size:  7.1 KB


    Code:
    Public Class Form3
        Private Vb6 As New vb6ex
    
        Private Sub Form3_Load(sender As Object, e As EventArgs) Handles MyBase.Load
    
            Using g As Graphics = Me.CreateGraphics
                Vb6.dpix1 = g.DpiX
            End Using
    
            Dim pix As Integer = Vb6.TwipsToPixels(1440)
    
            MsgBox("1440 twips = " & pix & " pixels")
    
        End Sub
    
    End Class
    
    Public Class vb6ex
        Public dpix1 As Single
    
        Public Function TwipsToPixels(ByVal twps As Integer) As Integer
    
            Return CInt(twps * dpix1 / 1440)
    
        End Function
    
    End Class

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Featured


Click Here to Expand Forum to Full Width