VS 02/03 - Converting Boolean Vars Into Integer

Aug 1, 2009

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.

View 1 Replies


ADVERTISEMENT

.net - Comparing Integer And Integer Results In Boolean?

May 28, 2009

I'm just writing a bit of code to compare an id of integer with an id of integer? for example:

Dim id As Integer = 1
Dim nullId As Integer? = Nothing
Dim areEqual As Boolean
areEqual = nullId = id

When I try to compile the code I get a compiler error: Option Strict On disallows implicit conversions from 'Boolean?' to 'Boolean'. Whilst it's very simple for me to work around this, I was hoping that someone might be able to explain what's going in the compiler to give this warning.

View 5 Replies

C# To VB: Converting To Boolean?

Jul 22, 2010

I am converting some C# code to VB, the following code is part of a function

if (bool.Parse(v["Parent"].ToString()))
{
e.Row.CssClass = "Parent";

[Code]....

The code throws an error "String was not recognized as a valid Boolean" But if I use this code

If CBool(v("Parent").ToString) = True Then
e.Row.CssClass = "Parent"
End If

It works fine, which is great

View 8 Replies

.net - Converting Boolean To Byte?

Feb 9, 2012

Why does casting a boolean to a byte in .NET give the following output?

Code Snippit:

Dim x As Boolean = 1
Dim y As Byte = x 'Implicit conversion here from Boolean to Byte
System.Diagnostics.Debug.Print( _

[Code].....

Why does True (which commonly is referred to as an integer representation of 1) convert to 255 when casted to a byte?

View 3 Replies

.net - Boolean VB Expression Returning False For Integer 1?

Jan 17, 2011

This is probably a really basic (no pun intended) question, but I can't seem to find an answer anywhere.Why does the result of func1 return False and func2 returns True? On every other test I have done, integer 1 is converted to boolean true and 0 to false. Works ok if I just set rtnValue to 1 or 0.

View 3 Replies

Casting A Boolean To An Integer Returns -1 For True?

Sep 1, 2010

I am working with some VB.Net code that seems to be casting a boolean value to an integer using CInt(myBoolean). The odd thing that is happening is that it returns -1 if the value is true. For example:

CInt(True) // returns -1
CInt(False) // returns 0

Is this common in other languages? I thought that a boolean would be 1 if true and 0 if false. Also, is there a way to make VB assign 1 to true instead of assigning -1?

View 5 Replies

VS 2010 Anyway To Customize A Variable To Use Both Integer And Boolean Value?

Aug 19, 2011

Is there anyway to customize a variable to use both an integer and a boolean value?For example. I am kind of making a simulation engine and using GDI as a visual aid, I am generating a grid of tiles for objects to be displayed, but I do NOT want to repaint all the tiles just the ones that have changed, so that I can save fps.So I thought if I could set a variable for the "tile number", "how many objects there are on a tile", and a boolean value for whether or not the tile needs repainted.[code]

View 2 Replies

Why Boolean True Is Equivalent To -1 If Identifier Type In Integer

Jan 24, 2012

Dim method1 = Function(x As Integer, ByRef y As Integer) As Boolean
If x = y Then
Return True
Else

[code]....

View 3 Replies

Convert An Integer Into A Boolean Array Based On It's Binary Bits

Jul 14, 2009

I am looking to convert an integer into a boolean array where each item in the array corresponds to a bit in the binary representation of the integer.

MyInteger = 3 '011 in binary
to
MyArray(2) = False
MyArray(1) = True
MyArray(0) = True

Also is there anyway to assign a value to an Integer in binary or hex (like MyInteger = 1010b or MyInteger = A7h)?

View 20 Replies

Converting Boolean And Date From Generic - Designer Does Not Accept A Simple CType?

Dec 6, 2010

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?

View 5 Replies

Converting A Word To An Integer

Jun 16, 2012

Is there any function in VB.NET to take the string "twenty" and convert it to 20?

View 2 Replies

Converting Integer To Time?

Dec 27, 2010

What would be the best method of converting an integer to time?

253 would be 00:02:53 123456 would be 12:34:56 1 would be 00:00:01 etc

Can I use convert.todatetime?

View 4 Replies

Converting String To Integer?

Jan 22, 2009

I have a textbox which the user will enter a number into. I then have a label control which will perform a maths operation and write out the resulting answer; atleast this is whant I want anyway however this is not happening.

The code I have so far is

Protected Sub btnWork_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnWork.Click
Dim Work As Integer

[Code].....

View 2 Replies

Converting Time So It Can Used In A Integer?

Mar 2, 2012

I'm working on some code in VB that can get the average time from the speed of button press. I've got the maths done however I'm having a problem converting a TimeSpan declaration into a Integer where it can be divided and made into a average.

Maths for code:

2nd click
click count = 2
average= current time / 1
so current = time click count - 1

[code]....

View 1 Replies

Asp.net - Converting Decimal In A Label To An Integer?

Mar 28, 2011

Currently using VS2008, VB.NET, SQL.

I have a FormView from a Data Source that is getting some fields that are stored as Decimals in the SQL Database.

I am grabbing the field from the FormView as such:

Dim AvgTicketL As Label = CType(frmMerchantProfile.FindControl("F10Label"), Label)

I need to take this value, and convert it to an Integer, then send it along to an API. I have the API Calls done, tested and working, but I'm getting an error as when it is getting this value, the API is returning "Must be an Integer" error.

What I have tried so far:

Dim AvgTicketL As Label = CType(frmMerchantProfile.FindControl("F10Label"), Label)
Dim AvgTicket1 As Integer
AvgTicket1 = Double.Parse(AvgTicket.Text)
Do something with AvgTicket1

I have also attempted to Round the Value, then convert it and call it - no luck.

Checking the value of AvgTicket1 (Writing it out to a Label or Response.Write) shows "100", where the database value was 100.00. But the API is still getting 100.00, apparently. Any other conversion method that I've attempted states errors that the Label cannot be converted to Integer.

What are some methods I can successfully convert this value to an integer from a label?

View 2 Replies

C# - Converting Into Integer In Excel Using EPPlus (asp.net)?

Jun 18, 2012

I am loading data into excel from datatable using LoadFromDataTable method then changed cell format to integer still it is showing error "The number in this cell is formatted as text or preceded by apostrophe". cell was showing to right side only and number format only on cell property.still I am not understanding why I am getting this error??.

Dim wsManufacturing As ExcelWorksheet = pck.Workbook.Worksheets.Add("Manufacturing")
wsManufacturing.Cells("A1").LoadFromDataTable(dtManufacturing, True)
Using col As ExcelRange = wsManufacturing.Cells(2, 2, 2 + dtManufacturing.Rows.Count, 2)

[code]....

View 3 Replies

VS 2008 Converting String To Integer?

Mar 17, 2009

i have a question... If i have a ListView and i have a subitem with the text 140.00, what can i do to make that string an integer?

View 25 Replies

Conversion - Converting Bytes To A Signed Integer

Nov 29, 2009

I have query that involves a cross-language operation, namely converting 4 SBytes to a signed integer. The source language for this operation is Java, which utilizes the ByteBuffer in order to extract a signed integer from the data stream. The inner workings of ByteBuffer are at best a black box to me, as I haven't been able to find any hints to what actually goes on when Java extracts the integer. [Code]

View 2 Replies

Converting Integer Number Into Currency Format?

Jul 12, 2010

How to convert the integer number into currency format in vb.net 2008.

View 4 Replies

Converting Timespan String Back To Integer

Feb 2, 2012

Working on a personal project.Originally had the file loaded had the program read a number and had trouble converting that number of total seconds into a TimeSpan.Finally got it working with a simple code, after COUNTLESS tried of different code.[code]Now I'm stuck converting that Timespan (in the DD:HH:MM:SS format) back to a integer of total seconds.Tried a bunch of codes I could think of but it was time that I had a fresh idea from other people.

View 13 Replies

VS 2008 What To Name Boolean Data Member And Boolean Method

Nov 17, 2009

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

[code].....

View 8 Replies

Make Constant Color Vars?

Aug 3, 2011

I need to put a color as a constant or readonly variable that the entire application can access but not edit. Currently I have a public variable in a module assigned to a color, is it possible to make it a constant variable?

View 2 Replies

Testing Vars In Intermediate Window?

Jun 22, 2009

Running through some basic tutorials and wanted the test the value of a variable i have created. How do I go about doing this in the intermediate window??

The only way I can do this is by creating a msgbox and then outputing the string var in the msgbox (var) to get the value I am after. Is there a way of doing this in the intermediate window??

I tried the following. but had no luck...

? ckstatevar

My code is as follows:

Private Sub ckboxDexter_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ckboxDexter.CheckedChanged
Dim ckstatevar As Single = ckboxDexter.CheckState

[Code].....

View 4 Replies

.net - Basic String Comparison - Comparing The Vars Gives A False

Aug 5, 2009

after slicing and dicing, i got 2 vars with the following values in vb.net:

strTag = "&lt;#<span class=SpellE>vermittler_person_Name</span>&gt;"
tmp = "&lt;#<span class=SpellE>vermittler_person_Name</span>&gt;"

Comparing the vars gives a false:

strTag = tmp ' ==> false

Comparing the values directly right there gives a true:

"&lt;#<span class=SpellE>vermittler_person_Name</span>&gt;" = "&lt;#<span class=SpellE>vermittler_person_Name</span>&gt;" ' ==> true

Both are strings, i tried all kinds of stuff: string.compare, string.equals, also regex etc. etc. everything works perfect with all the other strings with simlilar structure, just not and only not with "vermittler_person_Name" in the middle...

View 5 Replies

Make Boolean Column Editable (asp.net VB GridView Filled By DataTable That Has Boolean Column) ?

Oct 27, 2011

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

View 1 Replies

Difference Between Boolean And [Boolean]?

Mar 5, 2010

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

View 3 Replies

TCP - Send A String Held In A Var To An IP Address And Port Number Both Also Held In Vars

Dec 9, 2011

I wish to send a string held in a var to an IP address and Port number both also held in vars. I also wish to listen to a signals coming in on a particular port number so when particular strings are received I can trigger other transmissions.

View 2 Replies

Split File Down Into Vars From A Speech Mark And Non Delinted File?

Nov 15, 2011

I have a File i need to read and extract a few values from each line in the file. my problem as it stand the file i'm reading has some unconsistatcys as all of the Strings are seprated by " " but the integers are not they are Without any Speech marks to define them. I have thought of a methord to deal with this but i can't for the life of me think how to achive this.

As the file has unconstancys to be used with a standard " " extractor, the only consistancy is that there is allways a " before the integer and after attached to another column. this could be used i thought.

a Sample of the data is only one line:

[Code]...

View 4 Replies

Get This Message : Operator '+' Is Not Defined For Types 'integer' And '1-dimensional Array Of Integer'?

Sep 25, 2010

ive got some simple problem i cant understand how to solve.

str(1) is an array and integer(or double, tried both)
a(1) is an array and integer (or double, tried both)
a(1) = a(1) + 1
Label1.Text = str(1) + a

the big part is where i get: operator '+' is not defined for types 'integer' and '1-dimensional array of integer'.why do i get that message and what does it mean? how do i make the code do what i want?

View 1 Replies

Error : 'AddressOf' Expression Cannot Be Converted To 'Integer' Because 'Integer' Is Not A Delegate Type?

Aug 11, 2011

I faced an error when upgrading VB6 code to VB.NET. The error occurs at AddressOf WindowProc

AddressOf expression cannot be converted to 'Integer' because 'Integer' is not a delegate type

My declaration for SetWindowLong is:

Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA"(
ByVal hWnd As Integer,
ByVal nIndex As Integer,[code]....

What is the reason for the error I get?

View 1 Replies







Copyrights 2005-15 www.BigResource.com, All rights reserved