ads

Wednesday, November 29, 2006

How do I do it in VB.NET?

This tutorial explain some of the more common migrating problems from VB to VB.NET.
  • DoEvents

    VB6
    DoEvents

    VB7
    System.Windows.Forms.Application.DoEvents
  • App Object

    Get the full application filepath

    VB6
    App.Path & App.EXEName

    VB7 System.Reflection.Assembly.GetExecutingAssembly.Location.ToString

    Get the app's instance

    VB6 App.hInstance

    VB7
    System.Runtime.InteropServices.Marshal.GetHINSTANCE _(System.Reflection.Assembly.GetExecutingAssembly.GetModules() _(0)).ToInt32()

    Check for a previous instance

    VB6
    App.PrevInstance

    VB7
    Function PrevInstance() As Boolean
    If Ubound(Diagnostics.Process.GetProcessesByName(Diagnostics.Process.GetCurrentProcess).ProcessName)) > 0 Then
    Return True
    Else
    Return False
    End If

    End Sub
  • Graphics

    Load a picture

    VB6
    Picture1.Picture = LoadPicture(path)

    VB7
    Dim img As Image = Image.FromFile(path)
    Picture1.Image = img

    Load a icon

    VB6
    Me.Icon = LoadPicture(path)

    VB7
    Dim ico As New Icon(path)
    Me.Icon = ico

  • File I/0

    Read from a file

    VB6
    Open path For Input As #1
    Line Input #1, buffer
    Close #1

    VB7
    Dim fs As FileStream = File.Open(path, FileMode.OpenOrCreate, _ FileAccess.Read)
    Dim sr As New StreamReader(fs)
    Buffer = sr.ReadLine
    sr.Close

    Write to a file

    VB6
    Open path For Output As #1
    Write #1, buffer
    Close #1


    VB7
    Dim fs As FileStream = File.Open(path, FileMode.OpenOrCreate, _
    FileAccess.Write)
    Dim sr As New StreamWriter(fs)
    sr.Write(buffer)
    sr.Close

  • Errors

    Check for an error


    VB6
    On Error Goto errhandler
    ...
    errhandler:
    MsgBox(err.Description)

    VB7
    Try
    ...
    Throw New Exception("error description goes here")
    ...
    Catch e as Exception
    MsgBox(e.Description)
    End Try

  • Events

    Handling an event

    In VB7, there is a new keyword called AddHandler. AddHandler makes handling events a snap.

    AddHandler object.event, AddressOf procedure

Monday, November 27, 2006

C++ Intro…

Before you write your first program. Start with a prayer to God, that you “Succeed in learning C++”.

Now that all your hopes are high let us start. Please enter the following code exactly as shown, without any questions. (This is to inform you that the explanation will follow after the code.)

  1. #include
  2. int main()
  3. {
  4. cout<< “ What you do is what you get”;
  5. }

Although this may sound strange, once you compile this program you are a programmer.

<Warning: The numbered indentation is not to be included with the code while typing. It is only for your convenience>

Now let us read the first line. You read it as “Hash/Pound include eye-oh-stream-dot-h”

Iostream: Input Output stream. Don’t learn the definitions they automatically come to you.

You don’t pronounce the brackets while reading it loud, but is it a part of the code.

.h: Dot h files are known as header files. We place them in the beginning of the source code; it is like adding a DVD-Player to your deck. You don’t create .h files for now, nor would you add a DVD-Player to your deck each time you want to use it.

Iostream.h: Ok now you know what iostream and dot h stand for. If the terms input & output haven’t shed any light yet, keep reading. Iostream lets your program accept info/data/content or publish the same to the screen.

Wait we are still on the first line. Read the first line of source code again!

“Hash/Pound include eye-oh-stream-dot-h”

The Hash include is the standard form for telling the compiler that you want to include the Iostream.h file.

Now on line 2 we have int main(). Int is read as integer, read main() as main function. Without line 2 your program cannot work. On line 3 and 5 you have these {} braces.

Between the 2 braces all your code fits in. Make sure you enter line 4 exactly as it is. Pay attention to the punctuation.

Cout: See cout – It is the command with which you display text onto the screen

The <<>

Line 4 ends with a semi colon, don’t forget to type that, almost all c++ statements end with that. Now you may finally link, build and compile the code. Now you receive a message on a black terminal (Dos like): “What you do is what you get”


By: Amin Patel

Sunday, November 26, 2006

Open Read/Write File Code Download

i've decided to upload a sample code of my two previous post.

to download the code please click here
the password is: kodekruncher

Saturday, November 25, 2006

VB: Open Save File

Public Function SaveFile(File2Save As String, txtContent As String)

'Variable Declaration
Dim fLen As Integer

'Get the free file number
fLen = FreeFile

'Create Specified File
Open File2Save For Output As #fLen
Print #fLen, txtContent 'save the txtContent to the created file
Close #fLen 'Close the opened

End Function

Friday, November 24, 2006

VB: Open Read File



Public Function
 ReadFile(File2Open As String) As String

'Variable Declaration
Dim fLen As Integer
Dim tmp As String
Dim val As String

'Get the free file number
fLen = FreeFile

'Open Specified declared in File2Open Variable
Open File2Open For Input As #fLen
        
        Do ' Start of "DO" Loop
                Line Input #fLen, tmp ' Read the line in a file and store it in TMP Variable
                val = val & vbCrLf & tmp ' Store the readed line in the Val variable
        Loop Until EOF(fLen) 'End Loop until Eof file is True

Close #fLen ' Close the opened file

ReadFile = val ' pass value

End Function

Thursday, November 23, 2006

Welcome to The Code Cruncher

This Blog is all about programming and and i will be sharing some code that I made and some code that i would find intresting and usefull. Hope you guys will find this blog usefull

Programming Codes that would be posted here are.

  • Visual Basic
  • Visual Basic.Net
  • ASP / ASP.NET
  • Visual C#/ C++ /C
  • Java
  • Pascal
  • ASM
.

Google Search