|
Hi,
I have working with sockets i want to play youtube videos using sockets please help me
|
|
|
|
|
|
You can't. This violates the YouTube terms of service. You MUST use their player and nothing else.
Besides, if YouTube doesn't have a server listening for your client what are you going to connect to???
modified 9-May-13 10:22am.
|
|
|
|
|
I have to admit, this is probably about as basic as it gets, but I must confess ignorance on this, and I cannot seem to find an answer anywhere. It goes like this:
I have an If/EndIf block:
If ValueA And MaskA Then<br />
' Do stuff.<br />
End if
Now, I look at that and my first reaction is to knee-jerk and expect that the above If-line is written incorrectly since a bitwise operation has been evaluated but no condition on it has been defined. In other words, I would expect it to be written more like:
If ValueA And MaskA = 1 Then<br />
' Do stuff.<br />
End if
I ran the first example and, indeed, it seemed to work OK. So then it seemed that vb.Net can treat such an expression in a special way, assuming that such a line before being evaluated is "0" (False) and then POSSIBLY, not zero AFTER evaluation, making the result "True".
Then, based on that assumption, I needed a reverse logic, so that if the condition was False, it would execute rather than when it is True:
If Not (ValueA And MaskA) Then<br />
' Do stuff.<br />
End if<br />
However, that does not work since all that does is essentially take the binary digits and flip them, turning the result into a negative value (a signed integer).
So now it seems that the only solution is to set the block up as an If/Else block:
If ValueA And MaskA Then<br />
' Do stuff.<br />
Else<br />
' Do alternate stuff.<br />
End if<br />
That should ALWAYS work, I would tend to think.
But if my above logic has been perfectly consistent, then the 2nd example in this post, should also work, but with a test for the value "0":
If ValueA And MaskA = 0 Then<br />
' Do stuff.<br />
End if<br />
Alas, it failed, since vb.Net seems fixated on interpreting the result as having to be a Boolean, so my above logic is flawed somewhere. Even though evaluating the result in the Immediate window returns "0", the code does not execute.
What IS the vb.Net convention for using bitwise operators in an If-conditional statement?
Hopefully the answer to this question can solve the riddle of Global Warming and lead to cures for all diseases! )
|
|
|
|
|
If there is no explicit comparison in the condition expression, it is automatically compared to zero. Non-zero values result in True, zero results in False.
Your expressions seem to be dependant on having a bit be 0 or 1. You could rewrite your expression to be a bit more explicit by specifying what the result of the bitwise operation should be. For example, if you need to check the 7th bit for a 1, then you would use something like:
Private Const MASK As Integer = &H40
If (someValue And MASK) = MASK Then
End If
|
|
|
|
|
But that is similar to the following (in principal), which failed to execute the cotained code when the result was zero:
If ValueA And MaskA = 0 Then<br />
' Do stuff.<br />
End if<br />
|
|
|
|
|
|
If (ValueA And MaskA) = 0 Then<br />
' or<br />
If Not (ValueA And MaskA) Then
After testing, the first example works, the second does not. For the first one, I see now the importance of hierarchy and the parens. For the second, I don't think it works because it is performing a binary NOT on the result, thus turning it into a negative number (or just a huge unsigned integer). At any rate, since it is now a non-zero number, the final condition is "True", and the intended action fails.
|
|
|
|
|
Show the values of ValueA and MaskA you used for your test.
Do you understand that (6 AND 5) = 4 ?
|
|
|
|
|
treddie wrote: After testing, the first example works, the second does not
Oh, it works, just not the way to think it does.
The result of (ValueA And MaskA) results in an integer value, not True/False. That integer is compared to zero. If the result of the expression is non-zero, True is returned. The Not operator will invert that to False.
If the result of the expression is zero, False is returned, then inverted to True by the Not operator.
Withouting seeing the values of ValueA and Mask, it's pretty much all we can tell you.
|
|
|
|
|
The Not operator will invert that to False.
But that is not what happens. Here are some actual tests I performed:
The value and the mask in these examples are:
FileAttributes Value that contains a bit field that indicates whether a resource is a folder or a file.
Folder = 8208D, File = 8224D
Mask Bit mask that tests for the presence of a folder (16D).
Option Strict is NOT set.
_____________________________________________________________________________________________________
GOAL: Run code on "True" condition (Resource is a folder):
If (FileAttributes And FILE_ATTRIBUTE_DIRECTORY) Then
'Execute code.
End If
When FileAttributes = 8208D (Folder):
8208D (Folder) = 2 0 1 0 H
0010 0000 0001 0000 B
16D (Mask) = AND 0000 0000 0001 0000 B
_________________________________
Result 0000 0000 0001 0000 B <> 0, ("True"), Code executes as it should.
When FileAttributes = 8224D (File):
8224D (File) = 2 0 2 0 H
0010 0000 0010 0000 B
16D (Mask) = AND 0000 0000 0001 0000 B
_________________________________
Result 0000 0000 0000 0000 B = 0, ("False"), Code does not execute.
This is correct.
_____________________________________________________________________________________________________
GOAL: Run code on "False" condition (Resource is a file):
If Not (FileAttributes And FILE_ATTRIBUTE_DIRECTORY) Then
'Execute code.
End If
When FileAttributes = 8208D (Folder):
8208D (Folder) = 2 0 1 0 H
0010 0000 0001 0000 B
16D (Mask) = AND 0000 0000 0001 0000 B
_________________________________
Result 0000 0000 0001 0000 B <> 0, ("True"), Code WOULD execute, if left as is.
_________________________________
NOT 1111 1111 1110 1111 B <> 0, ("True"), Code executes when it SHOULD NOT.
When FileAttributes = 8224D (File):
8224D (File) = 2 0 2 0 H
0010 0000 0010 0000 B
16D (Mask) = AND 0000 0000 0001 0000 B
_________________________________
Result 0000 0000 0000 0000 B = 0, ("False"), Code does not execute, if left as is.
_________________________________
NOT 1111 1111 1110 1111 B <> 0, ("True"), Code executes as it should.
________________________________________________________________________________________________________________________________________________________________
I can only conclude from all of this, that an If condition without an equality can only execute code on "True", and never on "False".
|
|
|
|
|
OK. You should be testing the value of the bitwise operation against the value of the mask, NOT depending on an implied true or false.
|
|
|
|
|
That is the difference between a logical and a bitwise expression. In your expressions you cannot use NOT to invert from non-zero (implied TRUE ) to FALSE . I think as Dave suggests you need something like:
If (FileAttributes And FILE_ATTRIBUTE_DIRECTORY) Then
Else
End If
or even
If (FileAttributes And FILE_ATTRIBUTE_DIRECTORY) = FILE_ATTRIBUTE_DIRECTORY Then
Else
End If
Use the best guess
|
|
|
|
|
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.
|
|
|
|
|