Measurements Unit Conversion - Structure Of Class

Sep 14, 2011

I'm working on a Unit Conversion Module. I've found several good ideas here, as well as on CodeProject. My code looks very similar to this C# code at
(url)

From the following you'll probably gather that I'm pretty new to programming.I've created a Units base class that I inherit to create each unit type.[code...]

I need to create several different Unit types, such as Length, Pressure, etc. This is working well except for one issue. I'd like to be able to change the UnitType, and automatically update the UnitValue. Such that if the Unit object has a value of 1 and a type of Inch, and the type is changed to Cm, the value would update to 2.54.

Something like this.... I've seen examples of this, but the difference here is that, I can't specify the Covert function in my base class because it changes with each new UnitClass I create.
[code...]

I tried making the Property UnitType Overridable and creating a new Override Property for UnitType in each UnitClass that I created, but I failed to get that to work.

View 1 Replies


ADVERTISEMENT

Array Help Needed For Unit Conversion Application

Jun 7, 2010

I have a project to do in Visual Basic.My problem is that the outcome is always wrong (ex. instead of 2011 it gives 2000). And i cannot set as Desired unit the Inch(1) or feet(3), it gives the Infinity error. And if i put as Original and Desired unit the inch(1), the outcome is "Not a Number".[code]

View 2 Replies

Make A Program Which Basically Performs Unit Conversion?

Jun 18, 2012

Im trying to make a program which basically performs unit conversion. I have basically made two text boxes, one for the S.I. Units and the other for British Units. The general idea is that when i input any number in the S.I. Unit text box, it should display the answer in British Unit text Box and similiarly if i input any number in British Unit Textbox, the answer should be displayed in S.I.Unit textbox. Now the problem lies here that the code that i created is by using if else. now the compiler automatically gives me the correct result in the British box when i input the value in the s.i. unit box, but when i input the value in the british text box, it gives an error that :

"An unhandled exception of type 'System.InvalidCastException' occurred in Microsoft.VisualBasic.dll

Additional information: Conversion from string "" to type 'Double' is not valid."

Heres the part of the code.
Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
Dim p As String = "Pressure"

[Code].....

View 4 Replies

Class Structure - Large Structure That Has Lots Of Properties ?

Jan 5, 2010

I'm new to VB 2008 after having spent a long time with VB6, so I apologize if this is a stupid question. But I'd really like to have this straightened out.

Let's say I have a pretty large structure that has lots of properties.

Code:

Now say that I want an internal database with about 10 instances of this structure total, describing, say, 10 different products that a store sells. When these values are loaded from a database, they remain totally static. (However, they can be different each time a program loads)

Now say that I have a class. Each instance of this class is a type of that BaseProduct structure. Meaning, each instance of the class pertains to one of the 10 types of products that the store sells. However, this class has additional properties that pertain specifically to each instance, which are not static.

Code:

Now, the problem here is... If I have 200 different transactions, each one contains an instance of BaseProduct. BaseProduct is HUGE, and is largely redundant (only 10 types possible), so I think it's a little silly to include a whole copy of it with EVERY transaction. However, the Transaction class really needs information regarding the base product it pertains to. Is there a way to, instead of declaring a New BaseProduct in the Transaction class, to simply make one of the properties of the Transaction class a pointer to a BaseProduct variable?

In VB6, I would accomplish this by making a BaseProduct(10) array, and then giving each Transaction an ID number referring to an entry in that array. But in VB 2008, using class structure, this is impossible. I can't define the BaseProduct(10) array outside of a class in a namespace, and if I define it in the actual application's form, then the class loses modularity since it relies on the application that's using it.

View 11 Replies

VS 2008 Convert The XML Structure Into A Class Structure?

Apr 25, 2010

I'm having a problem that's driving me crazy; I can't understand how to convert the XML structure into a class structure (that I want to use to hydrate a XML document).

The XML document looks like this:

xml
<?xml version="1.0" encoding="utf-8"?>
<artists xmlns:opensearch="http://a9.com/-/spec/opensearch/1.1/" xmlns="http://www.spotify.com/ns/music/1">

[code]....

View 2 Replies

VS 2010 - String To Date Conversion In Structure

Dec 27, 2010

I am trying to convert text in a text box (txtEventDate.Text) to a date type in a structure: ThisEvent.EventDate (declared as date). The text in the textbox is of the form: 05/18/1927 (i.e. May 18th, 1927) and after looking long and hard thru the forums attempting several different things, like:

'ThisEvent.EventDate = CDate(Format("#" & txtEventDate.Text & "#", "mm/dd/yyyy"))
'ThisEvent.EventDate = Date.Parse(txtEventDate.Text & "12:01:00 AM")
'Date.TryParse(txtEventDate.Text, ThisEvent.EventDate)

The code is commented out because none of them convert the string to a date value (I know a date does not have a format and I have looked thru the MSDN). How can I stay logged and composing a thread past some arbitrary time limit that forces a re-login?

View 2 Replies

Application Which Communicate With One Data Logger Unit (temperature Monitoring Unit)

Jul 21, 2010

I have written one application which communicate with one data logger unit (temperature monitoring unit) and download records after some interval. Unit continuously send current temperature which I have to show on screen and after each one hour I have to download log (all records saved inside unit at max 1024) from unit.

Now problem is after downloading log, application get hang or what we called working in background and resume after some time. If I pause debugger in visual studio 2008 it show control at application start (sub main) with message as "application will resume here after completing execution of current function". There is nothing in output window. So how can i trace is there any events got spool or what actually application doing in background.

View 1 Replies

Unmanaged DLL Structure Conversion (unsigned Char Pointer)

Oct 28, 2009

I'm making a "wrapper" for an unmanaged DLL (written, I'm fairly certain in C). I have a c++ "wrapper" that I'm trying to convert to VB.net. I've got most of the program working, but I've hit a brick wall.

I'm trying to convert the following two structures from their c++ versions to their vb.net versions. I cannot be sure which is the problem because both must be passed at the same time. The error I am getting is thrown by the object and indicates "Invalid structure size specified". I can cause this error on other objects when I either don't set the dwSize variable, leave off a parameter or change the parameter type incorrectly. Note that the dwSize parameter is supposed to contain the size of each structure. I'm successfully calculating that for my other structures and I'm using the same method on these and the results appear correct, so I do not believe the problem is found there. The object uses a lot of structures and the rest of them are working. These two are the only ones with a) an unsigned character pointer b) an unsigned long array and c) doubles.

C++ versions:

CODE:

I don't think I'm missing any parameters - the help file seems to agree with me on this, but it's theoretically possible that there is something missing (though I don't think so for other reasons as well). My suspicion is that it's dwPalette, pImageData or pMaskData with (in my uninformed opinion) more suspicion on the pImageData and pMaskData.

View 7 Replies

Express Edition - Measurements Coverter?

Jul 14, 2009

I'm doing a project for school (I'm in Year 6, Primary School, Australia) and I'm trying to create a measurements converter with Visual Basic. Unfortunately I have a problem (and no teachers in the school have a clue on how to use visual basic).Basically the program just converts a specified amount of one unit of measurement and converts it to another unit of measurement.A message box then pops up telling the user the answer. Eg. A user specifies that they want 1 mile converted to 1 kilometre a message box will pop up telling them what the answer would be. In this case it would be about 1.6 kilometres.

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim double1 As Double = TextBox2.Text
Dim cb1 As String = ComboBox1.Text[code].....

View 6 Replies

VS 2008 Unit Converter Handling Multiple Unit Types

Apr 12, 2011

Does anyone have a nice sample of a unit convertor handling multiple unit types that I can integrate in my application? I have found this one, but it is only handling one type of unit. For example I want to convert weight as well as volume from and to imperial units.

View 8 Replies

Passing A Structure From One Class To Another Class In A Applications (VS2008)

Apr 7, 2010

I'm sure there are several ways of achieving my goal but I am after opinions on what you think is the best option. I'm writing a vb.net application which (amongst other thinks) interfaces with media players in the home. Because there are different types of media playersI'm trying to structure it so each type of media player has it's own class which interfaces to a management class which sits on top of all the different devices types.

The device classes are responsible for discovering the phsyical devices and returning that information up to the management class. A device class may be responsible for monitoring 1 or more physical devices so..

[Code]...

View 1 Replies

Use Reflection To Unit-test An Internal Class Within An Assembly When The InternalsVisibleToAttribute Is Not An Option?

Aug 26, 2010

I have a solution with two projects within:

Company.Project.vbproj
Company.Project.Tests.vbproj

Within the Company.Project.vbproj assembly, I have a class FriendClass.vb which scope is Friend (internal in C#).Now I wish to test this FriendClass.vb from within the Company.Project.Tests.vbproj assembly. I know about the InternalsVisibleToAttribute, but that is not an option in Visual Basic .NET 2.0, as it is only available with C#, in .NET 2.0 (see here).I would like to create myself a proxy class using this internal FriendClass from within my testing assembly, so that I could instantiate it and do the testings accordingly.

View 1 Replies

Asp.net - Structure A Class Inside A Class?

Jun 3, 2011

Currently, if I have different classes containing functions etc, I would structure them all in the 1 VB file titled whatever the main Class is. For example:

[Code]...

However, the problem with this is the file can become 1000s of lines long making hard to find portions of code. Is there a way I can store SubClass in a file such as MainClass.SubClass.vb so that its easier to locate classes? Or is there a better, more standard, way of doing this?

View 3 Replies

C# - Use A Structure Rather Than A Class?

Apr 10, 2009

In a recent project I was working I created a structure in my class to solve a problem I was having, as a colleague was looking over my shoulder he looked derisively at the structure and said "move it into a class". I didn't have any argument for not moving it into a class other than I only need it in this class but this kind of falls down because couldn't I make it a nested class?

View 5 Replies

.net - Where To Keep A Structure: Class, Module Or None

Apr 18, 2011

This is purely a coding practice question concerning VB.NET structures. Where do you keep one?As an example, I've created a structure for the simple purpose of keeping information organized, I'd like this structure to be stand-alone, not belonging to any class so I wouldn't have to access it through SomeClass.MyStructure but rather simply MyStructure. So, do I keep it in a separate class and import it into my namespace? Do I keep it in a module (Static class, essentially)? Do I just make a separate VB.NET code file and place is there (I would like it to live in a separate file). Just to clarify, I need this structure to be accesses by the whole application, not just a single class.

View 1 Replies

Class Structure For Three Outputs?

Feb 20, 2012

Could someone write me a Class structure for passing the data array below.

Function function1(Byval input1 as Double, Byval input2 as Double, Byval input3 as Double)
'code'
data.data1=value1

[code].....

View 4 Replies

Cannot Get Values From A Serializable Class And Structure

Feb 17, 2010

I have a serializable class and structure I created for an ArrayList to be access within a Web Application. The problem I am having is the count comes back as zero after calling New. I debugged the code and the Arrylist is being populated

View 3 Replies

Class/structure To Serialize JSON?

Mar 9, 2011

I am trying to figure out a class/struture to handle the following JSON format:

{
"ReturnData": [
{
"id": "msg2DoesNotExistName",

[Code]......

I may or may not have Data for ReturnData and SetValue (one or both at a minimum). I am trying to let the serializer handle most of the formatting without having to check for empty sections and single-item arrays.

View 1 Replies

Possible To Show Structure Of A Class In A Treeview?

May 31, 2009

is it possible to show the structure of a class in a treeview? if yes how

View 3 Replies

Reflection On Structure Differs From Class?

Jan 15, 2009

Code snippet:

Dim target As Object
' target gets properly set to something of the desired type
Dim field As FieldInfo = target.GetType.GetField("fieldName", _
BindingFlags.Instance Or BindingFlags.Public Or BindingFlags.NonPublic)
field.SetValue(target,newValue)

This snippet works perfectly IF target is set to an instance of a CLASS.However, if target is set to an instance of a STRUCTURE, the code does not actually change the value of the field. No error, but the value remains unchanged.And, oddly, if I'm stepping through code, watch the SetValue fail to do anything, and immediately go to the Immediate window and type exactly the same SetValue operation, that works.

Edit:

Per request from Jon Skeet, actual code:
Private Shared Function XmlDeserializeObject(ByVal objectType As Type, _
ByVal deserializedID As String) As Object[code].....

View 2 Replies

[2008] Size Structure In A Class?

Mar 6, 2009

I am making a class that has a property that I want to be of type System.Drawing.Size. I don't seem to be able to reference system.drawing from within my class, and therefor can't set my property's data type to Size. Anyone know how I might do this?

View 2 Replies

Build A Class Structure To Support Two Threads?

Nov 8, 2009

I have this application that users can make exams that contain exercises of different ... whatever. Anyway when student takes the exam he chooses it from a list and then all exercises are loaded from database. I wanted to make loading process faster by loading only first exercise data and putting others in background thread.

Actually in other parts of this application something like that is done but not by me. Basicaly an api class is built around BackgroudWorker and i can use this class to put certain functions of objects to be executed in background. The idea sounds great but in real life there are some problems with it. For example for historical reasons this application uses global functions and reader and uses global connection to Access database which means if in background something is being fectched from data base and you try to fetch from database in main thread then a „reader is already open" error occurs. To avoid this error if im doing something in main thread and want to fetch some data i have to move my function from main thread into background worker function list. And basically this in my opinion stinks cuz you end up with many delegātes, invoked checking and thre result... I was just thinking that there maybe is another way to allow (maybe with events) not put everything in background in case something is happening in bakcground but rather allow bgworker to finsih current thing, then do my thing and then resume bgWorker and not create havoc in code.

Basically i have to classes - exam and exercise that each implement many interfaces (like IExercise, IExerciseResult, IExerciseYesNo, IExerciseMultipleChoise etc.)And then i have DataBase classes like ExerciseDB, ExerciseResult etc. That have functions that preparē the sql params and call sqlHelper functions.And for example when i load up exam i go throug all exercises and call LoadData function that in turn calls ExerciseDB function selectData and then i put the returned data in Exercise object. And this type of thing of course would producē error if i at the same time would try to register the answer in database for another exercise. Ofcourse i could always check and put this in background... but as i said i'd rather want to work with database from both threads.

View 13 Replies

Class - Internationalization In .Net : Choosing The Right Structure Type?

Jan 22, 2010

I'm about to start translating my vb.net application, and I don't want to use the default methods provided by Visual Studio to do so. I need my application to be very light, and it nearly doubles it size to use the resources option.Therefore, I'm planning to use some thing like a class, of which I would have one instance per language. Since I don't want to distribute language files as separate files (I'd rather have them hard-coded), I would like to find an easy way to check if every field of the class is initialized. I was thinking of something like an Interface, where I would do something like this:

Public Interface Language
Dim HelloMsg As String
Dim GoodbyeMsg As String
End Interface

[code]....

It's obviously not the right way to do it (although I could use properties instead of vars), but I was wondering whether the was a way to have the compiler check that everything is translated and warn about it if not.

View 2 Replies

Create A List(of Bytes) Within A Class Structure?

Sep 2, 2011

I have the following Structure within a class[code]...

How do I efficiently use this list?[code]...

View 1 Replies

Creating A Lot Of Class And Structure Types For A Project?

Oct 12, 2009

Is there any performance hit (or other problem) to creating a lot of class and structure types for a project? I'm not talking about the number of objects existing in-memory during runtime; rather just defining a lot of object types during design time. I find myself making a lot of small classes and structures that are little more than simply packaging a few related variables together.

View 4 Replies

VS 2008 - Class Structure For Streaming Program

Mar 30, 2010

I'm trying to implement for the first time a library. With the event sub "client_TickPrice" I want to update a textbox. However nothing happens to my form when the "UpdateLast" sub is called from there.? The code was originally inside a Module (not a class like now), and set up as a console application. Probably there is a problem with the way I wrap my code, i.e. use of classes etc. This program is supposed to receive realtime stock/futures price data. Is it still a good way to start this code with the form, or should I make some type of console application?

Public Class Form1
Dim prog As New Program
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
prog.Main()
[Code] .....

View 8 Replies

Class Definition To Return Nested JSON Structure Without WCF?

Dec 10, 2011

I'm trying to return code like this (can be found here):

{"hotspots": [{
"id": "test_1",
"anchor": { "geolocation": { "lat": 52.3729, "lon": 4.93 } },

[code].....

View 2 Replies

Database - Import CSV To Class Structure As The User Defines?

May 28, 2010

I have a contact manager program and I would like to offer the feature to import csv files. The problem is that different data sources order the fields in different ways.I thought of programming an interface for the user to tell it the field order and how to handle exceptions.Here is an example line in one of many possible field orders:

"ID#","Name","Rank","Address1","Address2","City","State","Country","Zip","Phone#","Email","Join Date","Sponsor ID","Sponsor Name"[code]....

Notice that in one data field "Name" there is a comma to separate last name and first name and in another there is not.My plan is to have a line for each field (ie ID, Name, City etc.) and a statement "import to" and list box with options like: Don't Import, Business>Join Date, First Name, Zip

and the program recognizes those as properties of an object...I'd also like the user to be able to record preset field orders so they can re-use them for csv files from the same download source.Then I also need it to check if a record all ready exists(is there a record for Anson Call all ready?) and allow the user to tell it what to do if there is a record(ie mailing address may have changes, so if that field is filled overwrite it, or this mailing address is invalid,leave the current data untouched for this person, overwrite the rest).

While I'm capable of coding this...i'm not very excited about it and I'm wondering if there's a tool or set of tools out there to all ready perform most of this functionality...

View 2 Replies

Getting Field Values From A List Into Fields In A Structure Or Class?

Mar 21, 2012

I have a class (using a class rather than a structure only because I can set a default field value for the fields I declare in the class) and I'm using a web service that returns information (demographic information) in JSON. I am using LINQ to get the values of each "entry" from the returned list and in that, I have to parse through and pull out the actual data that I want.Here's how I have it doing right now (just a start, there are 44 of them total, thus my question which will follow the code):

Dim returnedStats = From ljo As Linq.JObject In returnedObject.SelectToken("results")
'
'
For Each stat As Linq.JObject In returnedStats

[code]....

View 2 Replies

Keeping Class Namespaces In Sync With Folder Structure

Oct 13, 2009

After being spoiled for years with C# automatically setting the default namespace for new classes to match my folder structure, I'm wondering if there is any way to get VB.NET to do the same?

I've been aware for awhile that it doesn't do this automatically but I've never really researched alternatives. keep my VB.NET class namespaces in sync with my project folder structures?

View 1 Replies







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