Posts tagged vb

Searching through all columns in datagridview

0

Assuming you are searching for the name John, the following procedure will search all existing columns regardless

Dim x As Integer = 0
 While x < DataGridView1.Rows.Count
 Dim y As Integer = 0
 While y < DataGridView1.Rows(x).Cells.Count
 Dim c As DataGridViewCell = DataGridView1.Rows(x).Cells(y)
 If Not c.Value Is DBNull.Value Or Nothing Then
 If CType(c.Value, String) = "John" Then
 MessageBox.Show("Found!")
 End If
 End If
 System.Math.Min(System.Threading.Interlocked.Increment(y), y - 1)
 End While
 System.Math.Min(System.Threading.Interlocked.Increment(x), x - 1)
 End While
 MessageBox.Show("Search complete!")
 End Sub

using c# and vb in the same web project

0

Can you have both c# and visual basic in the same web site project?

Definitely! It simply wouldn’t make sense from a new project standpoint, code reviews, coding standards, continuity, project maintenance, etc.

however, people still want it.  to-date i never really tried (and that’s been my answer).  I was presented with a usable scenario of why you may need (not want, need) to do this, so I finally tried it.  the answer: yes…kinda…sometimes.

let’s assume we have a web site structure like this:

we have the App_Code folder and a .cs and a .vb file in the same projects (separated into sub-folders).  note that the project sees them as folders (yellow folder icon) in the special folder.  each class within there basically has a “hello world” function only, like this in the c# file:


public string SayHelloCS()
    {
      return "Hello from CS";
  }
and the visual basic file has a similar function emitting "Hello from VB."

now, if you run default.aspx in this structure, this is what you will see:

The files ‘/WebSite5/App_Code/VBCode/Class2.vb’ and ‘/WebSite5/App_Code/CSCode/Class1.cs’ use a different language, which is not allowed since they need to be compiled together.

interesting?  probably not, but it makes sense…so how do we overcome.  we use a configuration option called .  here’s what we need to add to our <compilation> node in our web.config:


<compilation debug="false">
          <codeSubDirectories>
            <add directoryName="VBCode"/>
            <add directoryName="CSCode"/>
          </codeSubDirectories>
       </compilation>

once we add those codeSubDirectory nodes, let’s “look” at what the project structure looks like now:

as you can see the code folders are now “special” in the eyes of visual studio.  now if we browse default.aspx we will see:

Hello world from CS. Hello world from VB

       

Getting IP Address (VB NET 2008)

0

Note: if you’re not a beginner and just want to look for the code, you may skip these 1-6 steps and go straight to the sample code.

1) Let’s start with new project “Windows forms application”

2) Put one TextBox and a Button in the Form

3) Add reference to our project by clicking : Project –> Add Reference

4) Scroll down and select  “System.Net” as our reference. Click OK to proceed.

5) Open the Coding Window or you can just simply double click on the Button1, or you can also use F7 for shortcut.

6) Type “Imports System.Net” in General as shown in the picture below

7) Now the code part, on your Button1_Click event add this code as shown in the picture below

8) Run your program or press F5

Progress Bar Sample Code (VB NET 2008)

0

Picture Info:

—————————–

(A) Progress Bar, Properties :

Name = ProgressBar1

Minimum (value) = 0

Maximum (value) = 100

(B) Button, Properties :

Name = Button1

Text = Button1

(C) Timer, Properties:

Name = Timer1

Enabled = False

Interval = 100

Kode (F7) :

—————-

Public Class Form1
Private Sub Timer1_Tick(ByVal sender As  System.Object, ByVal e As  System.EventArgs)Handles Timer1.Tick
 
Static TikTok As Integer
 
TikTok = TikTok + 1
 
ProgressBar1.Value = TikTok
 
If ProgressBar1.Value = ProgressBar1.Maximum  Then
Timer1.Enabled  = False 'deactivate Timer1
 
TikTok  = 0 'set static value back to 0
End If
 
End Sub
 
Private  Sub Button1_Click(ByVal sender As System.Object, ByVal e As  System.EventArgs)Handles Button1.Click
Timer1.Enabled = True 'activate Timer1
 
Timer1.Interval = 100 'set interval to 100
 
ProgressBar1.Value = 0 'set ProgressBar value  to 0
End Sub
 
End Class
Go to Top