I have a 16*16 matrix and I'm trying to define them as a matrix series in vb.net. Then i make some visual shows with this matrix like led shows.
Dim n As Integer = 16
Dim l As Integer = 16
Dim x(n - 1, l - 1) As Integer
Dim i, j, k As Integer
For i = 0 To n - 1
For j = 0 To l - 1
For k = 1 To 256
If j= k mod16 then
buton(k) = x(i, j)
end if
Next
Next
Next***
I try to apply an algorithm. But it doesn't work. How can i accomplish this? Thanks for your interests..
OK I wrote something like this a while ago - I've adapted it to your needs and it runs ok on my pc. You need to create you array X like this
Dim x(15,15) As Button
To fill the array with buttons, use this method..
Private Sub InitializeArray()
Dim btnslist As New List(Of Button)
Dim btnNum As Integer
Dim btnName As String
Dim splitButtonName() As String
'add all the buttons to a list
For Each btnControl As Object In Controls
Dim btn As Button
'get button number and add it to the list if it is >0 and <=256
If TypeOf btnControl Is Button Then
btn = CType(btnControl, Button)
'get the button number
splitButtonName = Split(btn.Name, "n")
If CInt(splitButtonName(1)) > 0 And CInt(splitButtonName(1)) <= 256 Then
btnslist.Add(btn)
End If
End If
Next
'add the buttons to the matrix in the right order
For i As Integer = 0 To 15
For j As Integer = 0 To 15
For k As Integer = 0 To 255
btnNum = i * 16 + j + 1
btnName = "Button" & btnNum.ToString
If btnslist(k).Name = btnName Then
x(i, j) = btnslist(k)
Exit For
End If
Next
Next
Next
End Sub
Related
My code searches for certain numbers in textboxes and replaces them. The code however does not change the number if it is in a textbox that is created from a detail view(see figure 1). Do these not count as textboxes?
Figure 1
Dim Totalsheets As Integer
Dim target_text As String
Dim FirstPage As Integer
Dim replace_text As String
Dim result As String
Dim n As Integer 'count No. of text frames changed
Dim i As Integer 'count views for the sheet
Dim x As Integer 'takes the value of the first page of the old config
Dim y As Integer 'takes the value of the total number of sheets of the old config
Dim z As Integer 'takes the value of the number that needs to be added to update the zoning
Dim a As String 'takes the value of the letter found in the zoning box
Dim b As Integer
n = 0
Set osheets = odoc.Sheets
Set osheets = osheets.Item("DRAFT") 'makes sure only sheet "DRAFT" is edited
Set oViews = osheets.Views
Totalsheets = Totalsheets1.Value 'draws value from the textbox
FirstPage = FirstPage1.Value 'draws value from the textbox
For i = 3 To oViews.Count 'scans through all views in sheet
Set oView = oViews.Item(i)
Set oTexts = oView.Texts
For Each SrcText In oTexts 'scans through all text in view
x = FirstPage
y = Totalsheets
b = x + y
Do Until x = b + 1
z = x + Totalsheets
a = "A"
Do Until a = "[" 'goes from A to Z
result = SrcText.Text
target_text = " " & x & a 'gets space in front and letter at back to ensure only zone box are updated
replace_text = " " & z & a
If InStr(result, target_text) Then
result = Replace(result, target_text, replace_text)
SrcText.Text = result
n = n + 1
End If
a = Chr(Asc(a) + 1)
Loop
x = x + 1
Loop
Next
Next
Although the detail view identifier is a DrawingText, it does not belong to the DrawingTexts-collection.
You could access the DrawingText by searching in the view.
Better would be to rename the property of the view.
EDIT:
Example for using the (slower) selection:
Set oSel = oDoc.Selection
oSel.Clear
oSel.Add oView
oSel.Search "CATDrwSearch.DrwText,sel"
for i = 1 to oSel.Count2
Set oDrwText = oSel.Item2(i).Value
'do something with the text
next
I am trying to apply insertion sort on list of numbers in listbox, I know, I can sort it with built-in sorted function but I'm trying to practice algorithms by writing their code but can't able to do
this.
It just swap index 1 with 2 but not sorting all the numbers in ascending order.
What's the problem with my code?
Private Sub Button3_Click(sender As Object, e As EventArgs) Handles btnInsSort.Click
'Dim selectedItems = lstBox2.SelectedItems.Cast(Of [String])().ToList()
Dim arr = ListBox1.Items.Cast(Of [String])().ToList()
Dim j = ListBox1.SelectedIndex
Dim Key As String
For Each j In ListBox1.Items
j = 2
Key = ListBox1.Items(j)
i = j - 1
Next
While (i > 0 And ListBox1.Items(i) > ListBox1.Items(j))
ListBox1.Items(i + 1) = ListBox1.Items(i)
i = i - 1
ListBox1.Items(i + 1) = Key
End While
End Sub
There you go buddy. Picture the numbers in my array as items in your listbox
Dim SortNumber() As Integer = {5, 6, 3, 1, 8, 9, 4, 2, 7, 0}
Dim yCount As Integer = 0
Do
Dim CurNumber As Integer = SortNumber(yCount) 'Save current number
Dim xCount As Integer = 0
If yCount > 0 Then xCount = yCount - 1 ' start shift from here
Dim ReplaceNum As Boolean = False
Do While CurNumber < SortNumber(xCount) 'shift all position until current number is bigger then the one being shifted
If CurNumber < SortNumber(xCount) Then
ReplaceNum = True 'Number shifted save current number at the right position
SortNumber(xCount + 1) = SortNumber(xCount)
End If
xCount -= 1
If xCount = -1 Then Exit Do
Loop
If ReplaceNum = True Then SortNumber(xCount + 1) = CurNumber 'Place the current number at the right position
yCount += 1
Loop Until yCount = SortNumber.Count
I am attempting to loop the a specific set of frames within each Multipage page in my VBA User_Form. However, it does not seem like I can use a variable object name with each frame control like I can with the pages.
I am getting an error
object doesn't support this property or method
at the following line
For Each cCont in Me.MultiPage1.Pages(PageName).Frames(DataFrame).Controls
My Code
Do While x <= Me.MultiPage1.Pages.Count
PageName = "Page" & CStr(x)
DataFrame = "DataFrame" & CStr(x)
For Each cCont In Me.MultiPage1.Pages(PageName).Frames(DataFrame).Controls
You actually can't iterate the way you would think you could.
First, you need to iterate through all Pages of your MultiPage1.
Second, loop through all Controls inside the current Page , and check if they are of type Frame, if they are you can iterate inside the Frame but the syntax is a little different (see in the code below).
Code
Option Explicit
Private Sub IterateIn_MultiPage()
Dim x As Long, j As Long
Dim cCont As Control
For x = 0 To Me.MultiPage1.Pages.Count - 1 ' <-- loop through all MultiPage Pages
For Each cCont In Me.MultiPage1.Pages(x).Controls ' <-- loop through controls of current page
If TypeOf cCont Is Frame Then ' <-- check if control type is Frame
For j = 0 To cCont.Controls.Count - 1 '<-- loop through all items related to the current Frame collection
MsgBox cCont.Controls(j).Name '<-- display a message box
Next j
End If
Next cCont
Next x
End Sub
Thanks for the help on putting together the code #Shai, for anyone else wondering what the final code looks like here it is. This loops through each frame within each multipage and pastes the caption of checked checkboxes in my desired range.
Option Explicit
Sub IterateIn_MultiPage()
Dim x As Long, j As Long
Dim cCont As Control
Dim counter As Integer
Dim y As Integer
Dim Range As String
y = 1
For x = 0 To ImportData.MultiPage1.Pages.Count - 1
counter = 0
For Each cCont In ImportData.MultiPage1.Pages(x).Controls
Do While counter < 1
If TypeOf cCont Is Frame Then
For j = 0 To cCont.Controls.Count - 1
If cCont.Controls(j).Value = True Then
Range = "E" & y
If counter = 0 Then
Worksheets("Calculations").Range(Range) = cCont.Controls(j).Caption
counter = counter + 1
ElseIf counter = 1 Then
Worksheets("Calculations").Range(Range) = Worksheets("Calculations").Range(Range) & " & " & cCont.Controls(j).Caption
y = y + 1
End If
End If
Next j
End If
Loop
Next cCont
Next x
End Sub
i made a report for taking output of employees in a company.i made a code for that.but it only show the first items checked.how to impliment for loop in this.
Dim i As Integer
Dim j As Integer
Dim k As Integer
For i = 0 To Employee_Bank_dtl.CheckedListBox1.Items.Count - 1 Step i + 1
If Employee_Bank_dtl.CheckedListBox1.GetItemCheckState(i) = CheckState.Checked Then
Dim xx As String = (CType(Employee_Bank_dtl.CheckedListBox1.Items(i), DataRowView))("VC_BRNAME")
For j = 0 To Employee_Bank_dtl.CheckedListBox2.Items.Count - 1 Step j + 1
If Employee_Bank_dtl.CheckedListBox2.GetItemCheckState(j) = CheckState.Checked Then
Dim yy As String = (CType(Employee_Bank_dtl.CheckedListBox2.Items(j), DataRowView))("vc_empstatus")
For k = 0 To Employee_Bank_dtl.CheckedListBox3.Items.Count - 1 Step k + 1
If Employee_Bank_dtl.CheckedListBox3.GetItemCheckState(k) = CheckState.Checked Then
Dim zz As String = (CType(Employee_Bank_dtl.CheckedListBox3.Items(k), DataRowView))("vc_value")
Dim str = "xxxxxxxxxxxxxx"
conobj.readdata(str)
conobj._adpt.Fill(Me.DataSet10.BRANCH_MAST)
Me.ReportViewer1.RefreshReport()
End If
Next
End If
Next
End If
Next i
You should increment through the collection of items like this not the way you are doing it. You should be able to find the properties you are looking for. Set a break point within the inner loop and right click on quickwatch on the item and you will see all the properties of that item which will contain what your looking for.
For Each item In CheckedListBox1.Items
'set the item property to the right property that holds "VC_BRNAME"
If item.property = "VC_BRNAME" Then
End If
If item.checkstate.checked = True Then
End If
Next
Its my mistake replacing k + 1 to +1 in the 3rd loop will got the right answer
I am doing project in vb.net which is already done in vb6
I am having text box .I want to apply font (style,color,name,size) to selected text.
I am able to do this ..& want to create bitmap of this textbox text so that i can create matrix of 0,1,2,3 digits if text color is red then 1 digit,green-2,orange-3
Following code is done in vb6 but i am not getting some properties in vb.net like
picture1.point
picture1.print (here picture1 is picture box)
here Led is array of (digits 0 or 1 or 2 or 3 )
converttodis is functiont that converts each letter into array
Code is here
Private Sub CmdPreview_Click()
On Error Resume Next
Dim i
Picture1.Cls
lRow = 0
Lcol = 0
ReDim Led(Picture1.TextHeight(TxtMsg.Text), Picture1.TextWidth(TxtMsg.Text))
For i = 1 To Len(TxtMsg.Text)
TxtMsg.SelStart = i - 1
TxtMsg.SelLength = 1
Picture1.Font = TxtMsg.SelFontName
Picture1.FontSize = TxtMsg.SelFontSize
Picture1.FontBold = TxtMsg.SelBold
Picture1.FontItalic = TxtMsg.SelItalic
If Mid(TxtMsg.Text, i, 1) <> vbCr Then
Picture1.Print Mid(TxtMsg.Text, i, 1)
ConvertToDis i, TxtMsg.selcolor
ElseIf Mid(TxtMsg.Text, i, 2) = vbCrLf Then
i = i + 1
lRow = lRow + Picture1.TextHeight(Mid(TxtMsg.Text, i - 2, 1))
Lcol = 0
Else
Picture1.Print Mid(TxtMsg.Text, i, 1)
ConvertToDis i, TxtMsg.selcolor
End If
Next
End Sub
Public Function ConvertToDis(ByVal i As Long, ByVal col)
Dim CX, CY, f, f1, F2
Dim lsubrow, Lsubcol As Integer
lsubrow = lRow
Lsubcol = Lcol
For CY = 0 To Picture1.TextHeight(Mid(TxtMsg.Text, i, 1))
For CX = 0 To Picture1.TextWidth(Mid(TxtMsg.Text, i, 1))
If Picture1.Point(CX, CY) < vbWhite - 4300000 Then
If col = 255 Then
LedCol(lsubrow, Lsubcol) = 1
ElseIf col = 65280 Then
LedCol(lsubrow, Lsubcol) = 2
ElseIf col = 33023 Then
LedCol(lsubrow, Lsubcol) = 3
Else
LedCol(lsubrow, Lsubcol) = 0
End If
DoEvents
Lsubcol = Lsubcol + 1
Next
lsubrow = lsubrow + 1
Lsubcol = Lcol
Next
Picture1.Cls
Lcol = Lcol + Picture1.TextWidth(Mid(TxtMsg.Text, i, 1))
End Function
for LONG word output is like this
000000000000000000000000000000000000000000000000000000
000000000000000000000000000000000000000000000000000000
000000000000000000000000000000000000000000000000000000
000000000000000000000000000000000000000000000000000000
000011111000000011111100001111101111000111110000000000
000001110000001111111110000111100111001111111100000000
000001110000001111000110000111100110011110001110000000
000001110000011111000011000111100110111110001000000000
000001110000011010000011000111100110110110000000000000
000001110000011010000011000111110110110111111110000000
000001110000011010000011000110110110110110001111000000
000001110000011010000011000110111110110111111110000000
000001110000011110000011000110011110111100001110000000
000001110000101110000111000110011110011100001110000000
000001110011100111001110000110001110011110001110000000
000011111111110011111100001111001110000111111110000000
000011111111110011111000011111001110000111111111000000
000000000000000000000000000000000000000000000000000000
000000000000000000000000000000000000000000000000000000
000111111111111111111111111111111111111111111111110000
000000000000000000000000000000000000000000000000000000
000000000000000000000000000000000000000000000000000000
000000000000000000000000000000000000000000000000000000
000000000000000000000000000000000000000000000000000000
From Graphics for Visual Basic 6.0 Users:
In Visual Basic 2008, the Point method no longer exists. You can use the System.Drawing.Bitmap.GetPixel(System.Int32,System.Int32) method to retrieve a color value from a bitmap. For forms or controls that do not contain a picture, you can query the BackColor property.
In Visual Basic 2008, the DrawString method is used to display text. The font is determined by a Font object, and the color is determined by a Brush object; both are passed as parameters to the DrawString method. The DrawString method also has X and Y parameters that determine the starting location for the text. There is also an optional Format parameter that takes a StringFormat object, allowing you to display text vertically.