473,395 Members | 1,647 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

What the follow line do

What does the following line do?

Expand|Select|Wrap|Line Numbers
  1. Dim num As Single = CSng(-((num2 = Single.MinValue) > False))
Apr 11 '12 #1
3 1689
Frinavale
9,735 Expert Mod 8TB
It instantiates a Single type based on the return value from the CSng Function.

The CSng function converts an expression to type Single.

The value that it is converting is the result of:
Expand|Select|Wrap|Line Numbers
  1. -((num2 = Single.MinValue) > False)
If you break it down:

You are checking to see if the num2 value is equal to the Single.MinValue (-3.402823e38)

This will return a boolean type (true or false)

For some reason you are checking to see if this returned value is greater than false. Since true/false is just a yes/no, or 1/0 this is strange and could possibly throw errors.

I'm going to assume that when you use the [icode]>[icode] operator on a boolean, that it casts it into a number in order to do the comparison.

So, assuming that true=1 and false=0, you are checking to see if the result returns true since true>false.
This is not needed and is quite confusing.

Anyways, the code determines if num2 is equal to -3.402823e38...it then checks to see if the result is greater than false (in other words it checks to see if it is true).

Then the you are setting the true or false value to it's negative (flipping it). Assuming you aren't given any errors when you set a boolean to it's negative value.

The CSng function then converts the resulting (flipped) true or false into a Single.

I have no idea what you are trying to accomplish.
This code really is nonsensical.

In the end, assuming you don't have any errors thrown when you treat booleans as numbers, num will be instantiated as a -1 or 0 depending on the result of checking num2.

My advise to you: Treat booleans as booleans and treat numbers as numbers. Don't cast between them unless you know what you are doing and have a very specific reason for doing so.
Apr 11 '12 #2
Killer42
8,435 Expert 8TB
In VB 6 and earlier versions, while False is 0 as expected, True is actually -1. So a boolean value can never be "> False". However, that code is most certainly not VB6.

Using a boolean value as a number really isn't a problem, as long as you remember that True is negative. For example sometimes if I want to do something like
Expand|Select|Wrap|Line Numbers
  1. If Flag = True Then
  2.   Value = Value + 1
  3. End If
I will code it as
Expand|Select|Wrap|Line Numbers
  1. Value = Value - Flag
The end result is the same, it's just a little shorter to code. If the Flag is False, it subtracts zero. If True, it subtracts -1 which is the same as adding 1.
Apr 22 '12 #3
Frinavale
9,735 Expert Mod 8TB
Thanks Killer,

I learned something new today.
Apr 25 '12 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

8
by: Kim Forbes | last post by:
I am learning Javascript; and most books only give you partial definitions for the functions they show you. Here is a line of code from a browser sniffing function: var isWin =...
1
by: vishal | last post by:
What does #line 182 parser.y mean in a C program?
10
by: bob | last post by:
Hello, I use Microsoft Visual C++ .NET (version 7.1.3088) Sometimes (with big codes?) when I get a compile error and click on the error, the cursor is placed next to the wrong piece of code. The...
4
by: sam | last post by:
Hi, My question is how to use php on command line in windows
3
by: prabhu_anic | last post by:
can someone pl. tell me what do we exactly mean by COMMAND LINE ARGUMENTS and how to implement them in the programs.........
14
by: Samant.Trupti | last post by:
Hi all, I have some code that I am unable to understand. Can you please help? int _tmain(int argc, _TCHAR* argv) { // Initialize COM environment. ccLib::CCoInitialize...
10
by: Itaichuk | last post by:
Hi I read in several CSS tutorials that block-level elements, such as <div& <pare rendered with an implicit line break before and after. I set to test this out using the following HTML: I...
13
by: Rafael Anschau | last post by:
159: static PartsList GlobalPartsList; 160: }; 161: 162: PartsList PartsList::GlobalPartsList; I would understand if it initialized the object GlobalPartsList with some value, but as it is...
9
by: antar2 | last post by:
I am a starter in python and would like to write a program that reads lines starting with a line that contains a certain word. For example the program starts reading the program when a line is...
1
by: rameshjumgam | last post by:
My Environment:Linux 2.6.18-194.el5PAE #1 SMP Tue Mar 16 22:00:21 EDT 2010 i686 athlon i386 GNU/Linux My script is like #!/bin/bash if ; then while line='line' do ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.