I am interfacing my pc to a device called a MiniBee which is basically a usb digital output adapter to allow electronic devices to be controlled by the pc. So, I need to be able to individually address the output channels of this device, the only problem is the DLL supplied with it will only accept an integer value which represents a binary instruction if that makes any sense. I have basically got 8 public boolean vars OUT1, OUT2 etc that I need to use to turn on/off the outputs by them being set to true/false.
So there are say 8 digital output channels to operate and it has to work like this: SetOutputs(1) would turn on output 1 and turn all others off SetOutputs(2) would turn on output 2 and all others off SetOutputs(3) turns on 1 and 2 and all others off
How to turn my public bool vars into an integer based on what is set to true/false if you get my meaning as there must be an easy way but working it out individually there are far too many possible permutations.
I am creating a 'generic input dialog': InputDialog(Of T).The idea is that I can create new instances of this dialog for different values of T. For example,I can create an InputDialog(Of String) and it displays a textbox.I create an InputDialog(Of Boolean) and it displays two radiobuttons (I could use a Checkbox, irrelevant).I create an InputDialog(Of Date) and it shows a DateTimePicker.
I do this by simply checking the type of T at run-time.In this way it is not really generic, as the dialog still has to know which type T is (which is usually not the case), but the generic is in the fact that the T can be multiple types that require a TextBox. For example, InputDialog(Of String), (Of Integer), (Of Single), (Of Double), etc, all simply display a TextBox (and it is validated later),so I still want to use generics as much as possible.Anyway, the result of the dialog is of course a property of type T. This property needs to return the value in the textbox, converted from string to T, OR the value in the DateTimePicker, converted from Date to T,OR the checked property of the 'Yes' radiobutton, converted from Boolean to T.In order to convert from any object to T I googled and found this
vb.net
Imports System.ComponentModel Public Class GenericTypeConverter Public Shared Function FromObject(Of T)(ByVal value As Object) As T Dim tc As TypeConverter = TypeDescriptor.GetConverter(GetType(T)) Return CType(tc.ConvertFrom(value), T) End Function End Class
I have to use this, I cannot simply CType a string to T since a String cannot be converted to any type T.So, my Result property looks like this at the moment:
vb.net
Public ReadOnly Property Result()[code].....
This actually works for Strings, Integers, Doubles, Singles, etc. I pass it the String in the textbox and it converts it to 'T'(note: T is then a String, Integer or Double!) just fine.So, it can convert a String to a String, Integer or Double without any problems (I am validating the text before using the Result property so it will always be a valid integer, double, etc).However, it does not work for a Boolean, nor for a DateTime. When I try that, it says "BooleanConverter cannot convert from System.Boolean" or "DateTimeConverter cannot convert from DateTime". I realize it is a bit of a strange thing, since the object already IS a Boolean or a Date(Time) so no conversion should be done at all, but this doesn't work in design-time because I need to return the objects as type T.I know that T will be Boolean when the value to be converted is a Boolean, and that T will be DateTime when the value to be converted is a DateTime, but the designer does not accept a simple CType. As I said, it does not accept this:
Return CType(rbYes.Checked, T) because 'Boolean cannot be converted to T'.
However, I did find a way to make it work, but it seems like a complete hack... I can assign the boolean to an Object and then convert that using CType:
Dim obj As Object obj = rbYes.Checked Return CType(obj, T)
This works, it's accepted during design-time, and it works during run-time, but it seems very wrong... Is there no better way to handle this?
From what I read it is a good convention to name a method that returns a boolean value with the prefix of "is" or "has". So in keeping with this convention I am trying to name a method in my program with this prefix but I am running Specifically I have a class called Day. It is a simple class with a few data members and one method that returns a boolean value of true or false. The name of the boolean variable is isSpecialDay. This class has a method called isSpecialDay which takes the date of the day, applies some criteria to the date and then sets the variable isSpecialDay to true or false. My problem is that the boolean variable is named isSpecialDay and so it the method. What should I do?
Public Class Day Private TheDate as String Private DayName as String
After Filling a DataTable in GridView's DataSource . A column with check box Type appears but it created as read only column and I can't enable it or make it editable... even i tried .readonly = false and still can't be edited
I ran some code through an automatic translator for C# to VB, and it translated some code like this:Public Property Title As [String]How is this different to Public Property Title As String
I am working on a little Hardware interface project based on the Velleman k8055 board.The example code comes in VB.Net and I'm rewriting this into C#, mostly to have a chance to step through the code and make sense of it all.
One thing has me baffled though:At one stage they read all digital inputs and then set a checkbox based on the answer to the read digital inputs (which come back in an Integer) and then they AND this with a number:[code..]
I have not done Digital systems in a while and I understand what they are trying to do but what effect would it have to AND two numbers? Doesn't everything above 0 equate to true?How would you translate this to C#?
I am using a boolean embedded in a for next loop. I thought the value would ALWAYS default to false inside this loop, but it seems to hold the value of true inside the loop, even when moving to another value of i. What's up with this?
For i as integer = 0 to 5 im b as boolean se boolean value later...
I am working on my project to connect to a site. As I have created a boolean to check in the mysql database whether if the username and password is true or false.
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
I just wanted to know if it's possible to get an if statement to accept two strings into the same text box. An example of my code so far is below: (although please note that the program does not accept the strings after the "Or" boolean)
Private Sub btnpreview_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnpreview.Click If cbox2.Checked Then
I'm taking a course in Visual Basic 2010 and I'm trying to get a grasp on this new term called a flag. I kind of understand that it has something to do with a boolean condition. I don't quite understand what a flag is. I see references to it using the term flag. I understand it has something to do when a boolean, a condition triggers a flag. But what is the flag.
I'm working with Visual Basic 2008 Express. My application opens with the Terms screen, a form that asks the user to declare his acceptance of certain terms and conditions or to decline. If he accepts, the app opens the main screen, giving him access to all the app's facilities. If he declines, the app gives him a message and then closes. Whether he chooses to accept or decline, the app puts his decision in My.Settings so that it can be used next time the app is opened. In this way he is presented with the Terms screen on the next opening if he declined on the last run. But if he accepted on the last run, he is presented with the main screen on his next opening.
All works fine when I do a debug run. But when I build and publish the app onto my desktop it opens with the Main screen instead of the Terms screen.
I'm creating a program in which I have a publicly defined boolean value.Public boolOverallStatus As Boolean = True
and I need to execute some code whenever the boolean value changes. In previous applications, an actual form item change handled this, but it can be changed by several different subs.How would I handle this? I'm looking through msdn, but it's rather confusing. In a nutshell: How to execute code when the event of a boolean value changing occurs.
Now when I run this code, the value of MyBase.Associate.IsAgent() is true. Yet at no point is Me.pnlAddComment.Visible evaluating to true. When I output the results as Response.Write statements, it shows IsAgent = True, pnlAddComment.Visible = False. When I run it in debug mode, placing the line break on the second line above to allow the set to occur: I put the mouse over IsAgent and it displays "True"; I put the mouse over pnlAddComment.Visible and it displays "False".
A Co-worker suggested that it's possible that it's Panel.Visible black box code in the getter that allows the assignment to occur but returns false because some parent object is set (at that point in the code execution) to False. I've reviewed the parent objects and at no time do any of them appear to be set to not visible.
If this were a reference type I might be convinced that some other process is modifying the reference between this assignment and when it is actually used (at Render), but this is happening right at this line of code.What would cause this boolean assignment to behave this way without throwing an exception?
Solution:The answer turned out to be a parent object in the control hierarchy located outside of the user control itself. Since nothing was explicitly set to false, and I agreed with @Shadow Wizard, @Damien_The_Unbeliever and @CodeMonkey1 that it had to be some outside control influencing the panel at that point, I decided to put a recursive while loop to test the parent of each user control in the hierarchy at that point:
Dim o as Object = Me.pnlAddComment.Parent While o IsNot Nothing Me.lblMessage.Text &= "<br />" & o.ID & ": " & o.Visible.ToString() o = o.Parent End While
Then I just ran this on the server and the output came back with the full visibility of each control in the chain. What ended up occurring is that this control was contained within a view control within a MultiView. This view control is expected to be visible as it is supposed to be the ActiveView for this particular call, but at the point in the life cycle when my code is run, the view has not been identified as the active view. Since it's not officially active, the view is implicitly false, and all child controls return a value of false when Visible is queried.
The rest of the assignments behave as expected from that point. The lblRating control is set to false (permanently) because at that moment the proper visibility setting for pnlAddComment is false. The lesson I've learned here is not to make control visibilities dependent on each other in this fashion when there is an alternative (and just as simple) method.
I want to perform a bitwise-AND operation in VB.NET, taking a Short (16-bit) variable and ANDing it with '0000000011111111' (thereby retaining only the least-significant byte / 8 least-significant bits).
Having a little issue with my boolean statement. It is not changing the value to true after you click it. Its a basic function just not working correctly and Im pretty stumped on why. I mean its a simple yes or no concept. The button is on or off is the basic concept.
Private Sub btn_Backhoe_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn_Backhoe.Click Dim InUse As Boolean 'Switch On/Off[code].......
i have a form with text boxes for username, initials, and password on.Also on this form are a few checkboxes which at the minute i simply want to save their state to SQL as true or false depending if ticked or not. The checkboxes or text boxes are not bound to anything, and are used only for creating a new record in the table.There is a gridview below these boxes showing already created records.The code im using to insert to SQL with is:
If String.IsNullOrEmpty(UsernameTb.Text) Then MsgBox("You must enter a Username!") Else[code].....
For some reason when i create a new record, it saves the check state as -1 for checked, and 0 for unchecked. the table columns are varchar(5) for the check boxes.Using checkboxname.checkstate doesent work either - that saves the state as 1 or 0 (as opposed to -1 and 0)On another form i made for editing existing entries, i have the same text boxes and check boxes, which are bound so they show the record details. when using that form to EDIT an entry, it saves the check box states as "True" or "False" as it should do.Im completely stumped here, because if i create a new user it then breaks the gridview showing users, because it throws up error messages about "-1 not being valid boolean" when it attempts to render each check box in a grid view. how i can make the insert save the check box state as boolean?
What is the best way to convert an int (bit value from SQL Server) to a Boolean value in vb.net? I am currently using Cbool, but believe this is now obsolete.
I am developing an application for multi user using vb.net with back end as ms-access. For the table name as employee_master, there is a column, name as student_profile having datatype as Yes/No .
I have a form which creates a new school talk appointment. In my database, there is a column called 'active' which is boolean (true or false). Then everytime I creates a new school talk appointment and added it to database, the active is automatically set to 'false'. how to make it set to 'true' instead?
with a better solution.I have a .NET method that takes in 20+ boolean values, passed in individually.For each parameter that is true I need to add a value to list. Is there a more efficient way to add the values to the list besides have an if statement for each boolean?
Example: Public Function Example(ByVal pblnBool1 as boolean, _ ByVal pblnBool2 as boolean, _
I have 8 boolean variables and i need to be able to add an email to an email string for each boolean that is true. I dont't know how to do it without writing a million if statements. Here is some of what i have:
if bIsBlue then strEmailTo = strSalesEmail strEmailTo = strEmailTo & ", " & varBlueGrp End if
I'm trying to read a boolean value from a table. For some reason, when the statement executes it kicks me out of the method and back out to .show() method. The data read takes place in a procedure that is called by the Form_Load procedure. Any idea why it's kicking out? I've tried several versions of the command but with zero change. Here's my code. The offending command is in line 51. Every time I run debug I get to that line and then am kicked back out to my form.show() method.The end goal is to read a Boolean value Posted. If it is false then we read the data from this table to an accounts table to post the payments that are pending.
Imports System.Data.OleDb Public Class BankForm Dim con As New OleDbConnection Private Sub BankForm_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Currently I have been writing subroutines in a activex dll to carry out functions in my main program but I have hit a little snag when trying to return a function when an if statement is triggered. What I want to do is for the dll to check if a function in the my.settings of the main program is true/false and if it turns out that it is true/false in the settings it will trigger the if statement in the dll which will then send data back to the main program - seem simple? I am also wondering, can you transfur boolean settings for enabled textboxes through functions stated in the subroutine of the dll?