|
That is the conclusion I came to in an earlier post. But I needed to understand why, and now I think I get the behavior. It's kind of like that old saying, "You can prove a positive, but you can't prove a negative." At least not without that extra Else clause thrown in.
|
|
|
|
|
treddie wrote: It's kind of like that old saying, "You can prove a positive, but you can't prove a negative." At least not without that extra Else clause thrown in. Well that's not quite the issue. The issue is that you are using a bitwise operation whose result will be some number of 1 bits, including zero. If you than apply the NOT operator (which is also a bitwise operator) to that result you will get the bitwise complement. Neither of these is a boolean expression so their results are neither TRUE nor FALSE , they are just some number of bits from 0 to hex FF etc. If the result has any bits set then it is generally assumed to be TRUE in an IF clause; if it has no bits set then it is assumed to be FALSE . But applying the NOT operator to a non-zero result, can still give a non-zero answer. If you want strict boolean tests then you must include a comparison operator in the expression, as I did in the second example of my previous answer.
Use the best guess
|
|
|
|
|
|
treddie wrote: After testing, the first example works, the second does not. You need to show us the values of ValueA and MaskA , so we can try to figure out why.
Use the best guess
|
|
|
|
|
|
|
I am new in VB.Net programing. please help me to solve this problem.
Private Sub frmRX_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim Gename As String = "SELECT GName, GID FROM GenericName ORDER BY GName"
Dim cmdGname As New SqlCommand(Gename, con)
Dim daGname As New SqlDataAdapter(cmdGname)
daGname.SelectCommand.CommandText = cmdGname.CommandText.ToString()
Dim dtGname As New DataTable()
daGname.Fill(dtGname)
ddlGname.DataSource = dtGname
ddlGname.DisplayMember = "GName"
ddlGname.ValueMember = "GID"
ddlGname.AutoCompleteMode = AutoCompleteMode.SuggestAppend
ddlGname.AutoCompleteSource = AutoCompleteSource.ListItems
End Sub
Private Sub ddlGname_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ddlGname.SelectedIndexChanged
Dim ComName As String = "SELECT ComID,ComName FROM View_MedicineInfo WHERE GID = '" & ddlGname.SelectedValue.ToString() & "' GROUP BY ComID, ComName"
Dim cmdComName As New SqlCommand(ComName, con)
Dim daComName As New SqlDataAdapter(cmdComName)
Dim dsComName As New DataSet()
daComName.Fill(dsComName)
ddlComName.DisplayMember = "ComName"
ddlComName.ValueMember = "ComID"
ddlComName.DataSource = dsComName
But here
daComName.Fill(dsComName)
I got this error
Conversion failed when converting the varchar value 'System.Data.DataRowView' to data type int.
i have observed that if i put direct value like '1579' instead of & ddlGname.SelectedValue.ToString() & , it works fine
|
|
|
|
|
Try
Dim ComName As String = "SELECT ComID,ComName FROM View_MedicineInfo WHERE GID = " & ddlGname.SelectedValue & " GROUP BY ComID, ComName"
|
|
|
|
|
sorry, still i,m getting error[Operator '&' is not defined for string "SELECT ComID,ComName FROM View_M" and type 'DataRowView'.]
If use '" & ddlGname.SelectedValue & "' error[Operator '&' is not defined for string "SELECT ComID,ComName FROM View_M" and type 'DataRowView'.]
if use '" & ddlGname.SelectedValue.ToString() & "' error[ Conversion failed when converting the varchar value 'System.Data.DataRowView' to data type int.]
if i use direct value like '1234' instead of '" & ddlGname.SelectedValue.ToString() & "' it is ok
|
|
|
|
|
I would put a breakpoint on the ComName line and step through and see what the line shows.
that will tell you what your query is using.
Every day, thousands of innocent plants are killed by vegetarians.
Help end the violence EAT BACON
|
|
|
|
|
Read the message again. You're trying to convert an entire DataGridViewRow to an integer and there is no implicit conversion for that. You need a single value from the row, not the entire row itself!
|
|
|
|
|
Thank you for your reply. Finally I have solve this.
|
|
|
|
|
Hi I'm using Visual studio 2010 i'm creating a invoice billing software. i can access the data from database to datagridview and calculate the sum of all products. now i want a print function so i need to make a report please help me out this
Thanks in advance.
Public Class Form1
Dim ID As String = Nothing
Dim pname As String = Nothing
Dim qty As UInteger = Nothing
Dim rate As Decimal = Nothing
Dim amt As Decimal = Nothing
Dim i As UInteger
Dim count As UInteger = Nothing
Dim totalAmt
Dim salesTax
Dim salesTaxRate
Private Sub AddProduct_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles AddProduct.Click
Dim MaxRows As UInteger = Nothing
Dim pid As String
Dim found As Boolean = False
Dim Sql As String
Dim count As UInteger = Nothing
Dim con As New OleDb.OleDbConnection
con.ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Users\IMPossible\Music\Project\BillingInvoice\BillingInvoice\InvoiceDatabase.accdb"
count = count + 1
con.Open()
Dim productAdapter As OleDb.OleDbDataAdapter = Nothing
Dim productDataSet As New DataSet
Dim validID As Boolean = True
Dim validQty As Boolean = True
Sql = "SELECT Product_ID,Product_Name,Product_Rate FROM Product_Data"
productAdapter = New OleDb.OleDbDataAdapter(Sql, con)
productAdapter.Fill(productDataSet, "Prod_Data")
If txtID.Text = "" Then
MsgBox("Enter a valid ProductID")
validID = False
End If
If txtqty.Text = "" Then
MsgBox("Enter a valid quantity")
validQty = False
End If
If validID And validQty Then
Try
qty = CInt(txtqty.Text)
ID = txtID.Text.ToUpper
Catch ex As Exception
MsgBox("qty can't be empty")
End Try
End If
MaxRows = productDataSet.Tables("Prod_Data").Rows.Count
' Get the data for the new line item.
If MaxRows = 0 Then
MsgBox("No Product Found")
Else
i = 0
Do Until i >= MaxRows
pid = productDataSet.Tables("Prod_Data").Rows(i).Item(0)
If ID = pid Then
found = True
pname = productDataSet.Tables("Prod_Data").Rows(i).Item(1)
rate = productDataSet.Tables("Prod_Data").Rows(i).Item(2)
txtpname.Text = pname
txtrate.Text = rate
amt = qty * rate
txtamt.Text = amt
DataGridView.Rows.Add(New String() {ID, pname, qty, rate, amt})
End If
i = i + 1
Loop
If found <> True Then
MsgBox("NO product found")
End If
End If
con.Close()
' Clear the total text boxes.
txtTotalAmt.Text = ""
txtTax.Text = ""
txtGrandTotal.Text = ""
txtTotalProd.Text = ""
Dim totalAmt As Integer
For Each r As DataGridViewRow In DataGridView.Rows
Dim prodAmount As Integer = CInt(r.Cells(4).Value)
totalAmt += prodAmount
Next
txtTotalProd.Text = totalAmt
' Calculate the sales tax.
salesTax = 12.5
txtTax.Text = salesTax
' Calculate the total prod
Dim totalQuantity As Integer
For Each r As DataGridViewRow In DataGridView.Rows
Dim prodQty As Integer = CInt(r.Cells(2).Value)
totalQuantity += prodQty
Next
txtTotalProd.Text = totalQuantity
' Calculate the invoice total.
Dim invoiceTotal = totalAmt + salesTax
' Display the invoice totals.
txtTotalAmt.Text = FormatCurrency(totalAmt)
txtTax.Text = FormatCurrency(salesTax)
txtGrandTotal.Text = FormatCurrency(invoiceTotal)
End Sub
End Class
|
|
|
|
|
Since you're using Access as a database, it'd seem logical to create a report in Access itself. If this application is used by more than one person, I'd suggest you upgrade to Sql Server.
For more information on building reports, go here[^].
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
Hi.
For the life of me, I cannot get a TreeView Find to work. I have a list of drives, folders and subfolders in my TreeView. I have googled like crazy and either find repeated references to a very simple method, or convoluted methods that seem to apply to something else. Here is a very basic procedure that fails:
Private Sub TreeView1_AfterSelect(ByVal sender As System.Object, ByVal e As System.Windows.Forms.TreeViewEventArgs) Handles TreeView1.AfterSelect
Me.TreeView1.SelectedNode = Me.TreeView1.Nodes.Find("Client Supplied Files", True)(0)
End Sub
I put the Find method in the _AfterSelect event only because I was using that event as a test area to do the find. In other words...If I clicked on any node in the tree, the event would cause the selected node to change to the one specified in the search. But alas, no go.
I have to be missing something really simple here.
Thank you for any hints!
|
|
|
|
|
treddie wrote: I have a list of drives, folders and subfolders in my TreeView. How did you load them? Something similar to this[^]? In that case not all nodes will be loaded when the control shows, only the nodes that are expanded.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
Hm...I like that solution MUCH better. But in the interests of trying to understand why "my" version won't work (it was an online TreeView demo that I modified slightly), no, it was a fully recursive method. Please see code below:
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Go_cmd.Click
Dim drives As System.Collections.ObjectModel.ReadOnlyCollection(Of IO.DriveInfo) = My.Computer.FileSystem.Drives
Dim rootDir As String = String.Empty
For i As Integer = 0 To drives.Count - 1
System.Windows.Forms.Application.DoEvents()
rootDir = drives(i).Name
TreeView1.Nodes.Add(rootDir)
PopulateTreeView(rootDir, TreeView1.Nodes(i))
NextDrive:
Next i
End Sub
Private Sub PopulateTreeView(ByVal dir As String, ByVal parentNode As TreeNode)
Dim folder As String = String.Empty
Try
Dim folders() As String = IO.Directory.GetDirectories(dir)
If folders.Length <> 0 Then
Dim childNode As TreeNode = Nothing
For Each folder In folders
System.Windows.Forms.Application.DoEvents()
childNode = New TreeNode(folder)
parentNode.Nodes.Add(childNode)
PopulateTreeView(folder, childNode)
Next folder
End If
Catch ex As System.IO.IOException
parentNode.Nodes.Add(folder & ": Drive not Ready")
Catch ex As UnauthorizedAccessException
parentNode.Nodes.Add(folder & ": Access Denied")
End Try
End Sub
Private Sub TreeView1_AfterSelect(ByVal sender As System.Object, ByVal e As System.Windows.Forms.TreeViewEventArgs) Handles TreeView1.AfterSelect
If Text <> String.Empty Then
Dim arr As TreeNode() = TreeView1.Nodes.Find("Client Supplied Files", True)
For i = 0 To arr.Length - 1
TreeView1.SelectedNode = arr(i)
Next
End If
End Sub
End Class
|
|
|
|
|
Unless some other members beats me to it, I'll write a search-implementation tomorrow.
Now,
|
|
|
|
|
Thank you very much, and no rush.
|
|
|
|
|
Here is a code that I made by several examples that I found:
Public Class cTreeviewFind
Inherits TreeView
#Region "Functions"
Function SearchTree(ByVal root As TreeNode, ByVal text As String) As System.Collections.Generic.List(Of TreeNode)
Dim nodes As New System.Collections.Generic.List(Of TreeNode)()
If root.Text.ToUpper().Contains(text.ToUpper()) Then
nodes.Add(root)
End If
For Each node As TreeNode In root.Nodes
Dim subNodes As System.Collections.Generic.List(Of TreeNode) = SearchTree(node, text)
If (subNodes.Count > 0) Then
nodes.AddRange(subNodes)
End If
Next
Return nodes
End Function
Public Function FindNode(ByVal _nodeCollection As TreeNode, ByVal SearchVal As String, Optional ByVal CaseSensitief As Boolean = False, Optional ByVal CompleteValue As Boolean = False, Optional ByVal refind As Boolean = False) As TreeNode
Dim tmpNode As TreeNode = Nothing
Static bFoundSelectedNode As Boolean
If refind Then bFoundSelectedNode = False
If Me.SelectedNode.Equals(Me.Nodes(0)) Then
bFoundSelectedNode = True
End If
For Each _c As TreeNode In _nodeCollection.Nodes
If _c.Equals(Me.SelectedNode) Then
bFoundSelectedNode = True
End If
If bFoundSelectedNode = False Then
If _c.Nodes.Count > 0 Then
tmpNode = FindNode(_c, SearchVal, CaseSensitief, CompleteValue)
If bFoundSelectedNode = True AndAlso Not tmpNode Is Nothing Then
Return tmpNode
End If
End If
Else
If CaseSensitief Then
If CompleteValue Then
If _c.Text = SearchVal AndAlso _c.Equals(Me.SelectedNode) = False Then Return _c
If _c.Nodes.Count > 0 Then tmpNode = FindNode(_c, SearchVal, CaseSensitief, CompleteValue)
If Not tmpNode Is Nothing Then
Return tmpNode
End If
Else
If _c.Text.IndexOf(SearchVal) >= 0 AndAlso _c.Equals(Me.SelectedNode) = False Then Return _c
If _c.Nodes.Count > 0 Then tmpNode = FindNode(_c, SearchVal, CaseSensitief, CompleteValue)
If Not tmpNode Is Nothing Then
Return tmpNode
End If
End If
Else
If CompleteValue Then
If _c.Text.ToLower = SearchVal.ToLower AndAlso _c.Equals(Me.SelectedNode) = False Then Return _c
If _c.Nodes.Count > 0 Then tmpNode = FindNode(_c, SearchVal, CaseSensitief, CompleteValue)
If Not tmpNode Is Nothing Then
Return tmpNode
End If
Else
If _c.Text.ToLower.IndexOf(SearchVal.ToLower) >= 0 AndAlso _c.Equals(Me.SelectedNode) = False Then Return _c
If _c.Nodes.Count > 0 Then tmpNode = FindNode(_c, SearchVal, CaseSensitief, CompleteValue)
If Not tmpNode Is Nothing Then
Return tmpNode
End If
End If
End If
End If
Next
Return Nothing
End Function
#End Region 'functions
End Class
Jan
|
|
|
|
|
FINALLY! One that actually works! . Now the big $30,000 question is, why doesn't the method that MS and so many others suggest NOT work?
Me.TreeView1.SelectedNode = Me.TreeView1.Nodes.Find("Client Supplied Files", True)
|
|
|
|
|
treddie wrote: Now the big $30,000 question is, why doesn't the method that MS and so many others suggest NOT work? Here's a free answer to an expensive question; due to the difference between the nodes' key and it's label. The "find" method works on keys[^] (the name of the node), not on the text being displayed. If you only pass a single string when creating a node, it will not have a name. Try the example below and play a bith with it.
Imports System.Windows.Forms
Module Module1
Private TreeView1 As New TreeView()
Sub Main()
Using f As New Form
Dim btn As New Button
btn.Dock = DockStyle.Top
AddHandler btn.Click, Sub(s As Object, e As EventArgs)
Dim foundNodes As TreeNode() = TreeView1.Nodes.Find("Node 39", True)
If foundNodes.Length > 0 Then
TreeView1.SelectedNode = foundNodes(0)
TreeView1.Focus()
End If
End Sub
TreeView1.Dock = DockStyle.Fill
For i As Integer = 0 To 40
Dim key As String = String.Format("Node {0}", i)
Dim label As String = String.Format("Label {0}", i)
TreeView1.Nodes.Add(key, label)
Next
f.Controls.Add(TreeView1)
f.Controls.Add(btn)
f.ShowDialog()
End Using
End Sub
End Module
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
Heheh...Your code threw me for a second. It looks like you did a C#-to-vb conversion. But I figured it out and made the mods to get it to work in vb.Net. (I'm not a "C" guy). Here is my change to your translation, with a caption added to the button:
Imports System.Windows.Forms
Module Module1
Dim TreeView1 As New TreeView
Sub Main()
Using f As New Form
Dim btn As New Button
btn.Dock = DockStyle.Top
btn.Text = "Find ""Label 39"""
AddHandler btn.Click, AddressOf BClick
TreeView1.Dock = DockStyle.Fill
For i As Integer = 0 To 40
Dim key As String
key = String.Format("Node {0}", i)
Dim label As String = String.Format("Label {0}", i)
TreeView1.Nodes.Add(key, label)
Next i
f.Controls.Add(TreeView1)
f.Controls.Add(btn)
f.ShowDialog()
End Using
End Sub
Private Sub BClick(ByVal s As Object, ByVal e As EventArgs)
Dim foundNodes As TreeNode() = TreeView1.Nodes.Find("Node 39", True)
If foundNodes.Length > 0 Then
TreeView1.SelectedNode = foundNodes(0)
TreeView1.Focus()
End If
End Sub
End Module
This makes complete sense now...The name/key is NOT the text label. Although it is best to make sure the key = text, so that you don't get confused by the results.
|
|
|
|
|
treddie wrote: It looks like you did a C#-to-vb conversion. Thanks; no conversion, it was a new console-application in the VS-IDE
|
|
|
|
|
I'm curious what that app is?
|
|
|
|
|