Search Results

Search found 4472 results on 179 pages for 'vb'.

Page 7/179 | < Previous Page | 3 4 5 6 7 8 9 10 11 12 13 14  | Next Page >

  • C#'s equivalent to VB.Net's DirectCast?

    - by Collin Sauve
    This has probably been asked before, but if it has, I can't find it. Does C# have an equivalent to VB.Net's DirectCast? I am aware that it has () casts and the 'as' keyword, but those line up to CType and TryCast. To be clear, these keywords do the following; CType/() casts: If it is already the correct type, cast it, otherwise look for a type converter and invoke it. If no type converter is found, throw an InvalidCastException. TryCast/"as" keyword: If it is the correct type, cast it, otherwise return null. DirectCast: If it is the correct type, cast it, otherwise throw an InvalidCastException. EDIT: After I have spelled out the above, some people have still responded that () is equivalent, so I will expand further upon why this is not true. DirectCast only allows for either Narrowing or Widening conversions on inheritance tree, it does not support conversions across different branches like () does. ie: C#, this compiles and runs: //This code uses a type converter to go across an inheritance tree double d = 10; int i = (int)d; VB.Net, this does NOT COMPILE 'Direct cast can only go up or down a branch, never across to a different one. Dim d as Double= 10 Dim i as Integer = DirectCast(d, Integer) The equivalent in VB.Net to my C# code is CType: 'This compiles and runs Dim d as Double= 10 Dim i as Integer = CType(d, Integer) (Edit again, I was originally using strings, I changed it to double... sorry)

    Read the article

  • Java equivalent of the VB Request.InputStream

    - by Android Addict
    I have a web service that I am re-writing from VB to a Java servlet. In the web service, I want to extract the body entity set on the client-side as such: StringEntity stringEntity = new StringEntity(xml, HTTP.UTF_8); stringEntity.setContentType("application/xml"); httppost.setEntity(stringEntity); In the VB web service, I get this data by using: Dim objReader As System.IO.StreamReader objReader = New System.IO.StreamReader(Request.InputStream) Dim strXML As String = objReader.ReadToEnd and this works great. But I am looking for the equivalent in Java. I have tried this: ServletInputStream dataStream = req.getInputStream(); byte[] data = new byte[dataStream.toString().length()]; dataStream.read(data); but all it gets me is an unintelligible string: data = [B@68514fec Please advise. Edit Per the answers, I have tried: ServletInputStream dataStream = req.getInputStream(); ByteArrayOutputStream buffer = new ByteArrayOutputStream(); int r; byte[] data = new byte[1024*1024]; while ((r = dataStream.read(data, 0, data.length)) != -1) { buffer.write(data, 0, r); } buffer.flush(); byte[] data2 = buffer.toByteArray(); System.out.println("DATA = "+Arrays.toString(data2)); whichs yields: DATA = [] and when I try: System.out.println("DATA = "+data2.toString()); I get: DATA = [B@15282c7f So what am I doing wrong? As stated earlier, the same call to my VB service gives me the xml that I pass in.

    Read the article

  • VB.NET editing existing that with a form

    - by user127147
    Hi there, I have a simple questions that puzzles me. I need a little bit of refreashment with VB as I have been away for a while. I have a form that adds new contacts. New contacts are added by pressing an appropriate button and they appear as an entry in the list on the form. I try now to add an edit button that will edit existing entries. User will select a given entry on the list and press edit button and will be presented with an appropriate form (AddContFrm). Right now it simply adds another entry with the same title. Logic is handled in a class called Contact.vb Here is my code. Public Class Contact Public Contact As String Public Title As String Public Fname As String Public Surname As String Public Address As String Private myCont As String Public Property Cont() Get Return myCont End Get Set(ByVal value) myCont = Value End Set End Property Public Overrides Function ToString() As String Return Me.Cont End Function Sub NewContact() FName = frmAddCont.txtFName.ToString frmStart.lstContact.Items.Add(FName) frmAddCont.Hide() End Sub Public Sub Display() Dim C As New Contact 'C.Cont = InputBox("Enter a title for this contact.") C.Cont = frmAddCont.txtTitle.Text C.Fname = frmAddCont.txtFName.Text C.Surname = frmAddCont.txtSName.Text C.Address = frmAddCont.txtAddress.Text 'frmStart.lstContact.Items.Add(C.Cont.ToString) frmStart.lstContact.Items.Add(C) End Sub End Class AddContFrm Public Class frmAddCont Public Class ControlObject Dim Title As String Dim FName As String Dim SName As String Dim Address As String Dim TelephoneNumber As Integer Dim emailAddress As String Dim Website As String Dim Photograph As String End Class Private Sub btnConfirmAdd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnConfirmAdd.Click Dim C As New Contact C.Display() Me.Hide() End Sub Private Sub frmAddCont_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load End Sub End Class and frmStart.vb Public Class frmStart Private Sub btnAdd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAdd.Click frmAddCont.Show() End Sub Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDel.Click Dim DelCont As Contact DelCont = Me.lstContact.SelectedItem() lstContact.Items.Remove(DelCont) End Sub Private Sub lstContact_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lstContact.SelectedIndexChanged End Sub Private Sub btnEdit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnEdit.Click Dim C As Contact If lstContact.SelectedItem IsNot Nothing Then C = DirectCast(lstContact.SelectedItem, Contact) C.Display() End If End Sub End Class

    Read the article

  • Converting Python Script to Vb.NET - Involves Post and Input XML String

    - by Jason Shoulders
    I'm trying to convert a Python Script to Vb.Net. The Python Script appears to accept some XML input data and then takes it to a web URL and does a "POST". I tried some VB.NET code to do it, but I think my approach is off because I got an error back "BadXmlDataErr" plus I can't really format my input XML very well - I'm only doing string and value. The input XML is richer than that. Here is an example of what the XML input data looks like in the Python script: <obj is="MyOrg:realCommand_v1/" > <int name="priority" val="1" /> <real name="value" val="9.5" /> <str name="user" val="MyUserName" /> <reltime name="overrideTime" val="PT60S"/> </obj> Here's the Vb.net code I attempted to convert that: Dim reqparm As New Specialized.NameValueCollection reqparm.Add("priority", "1") reqparm.Add("value", "9.5") reqparm.Add("user", "MyUserName") reqparm.Add("overrideTime", "PT60S") Using client As New Net.WebClient Dim sTheUrl As String = "[My URL]" Dim responsebytes = client.UploadValues(sTheUrl, "POST", MyReqparm) Dim responsebody = (New System.Text.UTF8Encoding).GetString(responsebytes) End Using I feel like I should be doing something else. Can anyone point me to the right direction?

    Read the article

  • How to use SQL Expression Fields of Crystal Report 11.5 from VB.NET 2008

    - by Tareq
    I have the following SQL Expression Field in my Crystal Report 11.5 {fn CONCAT({fn CONCAT("SPR_PRODUCT"."PRODUCT_ID","SPR_PRODUCT_SUB_ITEM"."P_SUB_ITEM_ID" )},{fn CONCAT("SPR_PRODUCT_ITEM"."P_ITEM_ID","SPR_PRODUCT_GROUP"."P_GROUP_ID" )} )} It works well in the Preview Mode. But when I use the report in my VB.NET 2008 Project it says the following: Error in compiling SQL Expression : SQL Expressions can not be used in this report.. Error in File <...>.rpt: SQL Expression error: Error in compiling SQL Expression : SQL Expressions can not be used in this report... Please help me by telling how can I use the SQL Expression field in VB.NET ? Thanks in Advance.

    Read the article

  • Cannot iterate of a collection of Anonymous Types created from a LINQ Query in VB.NET

    - by Atari2600
    Ok everyone, I must be missing something here. Every LINQ example I have seen for VB.NET anonymous types claims I can do something like this: Dim Info As EnumerableRowCollection = pDataSet.Tables(0).AsEnumerable Dim Infos = From a In Info _ Select New With {.Prop1 = a("Prop1"), .Prop2 = a("Prop2"), .Prop3 = a("Prop3") } Now when I go to iterate through the collection(see example below), I get an error that says "Name "x" is not declared. For Each x in Infos ... Next It's like VB.NET doesn't understand that Infos is a collection of anonymous types created by LINQ and wants me to declare "x" as some type. (Wouldn't this defeat the purpose of an anonymous type?) I have added the references to System.Data.Linq and System.Data.DataSetExtensions to my project. Here is what I am importing with the class: Imports System.Linq Imports System.Linq.Enumerable Imports System.Linq.Queryable Imports System.Data.Linq Any ideas?

    Read the article

  • paypal API in VB.net

    - by StealthRT
    Hey all, i have converted some C# PayPal API Code over to VB.net. I have added that code to a class within my project but i can not seem to access it: Imports System Imports com.paypal.sdk.services Imports com.paypal.sdk.profiles Imports com.paypal.sdk.util Namespace GenerateCodeNVP Public Class GetTransactionDetails Public Sub New() End Sub Public Function GetTransactionDetailsCode(ByVal transactionID As String) As String Dim caller As New NVPCallerServices() Dim profile As IAPIProfile = ProfileFactory.createSignatureAPIProfile() profile.APIUsername = "xxx" profile.APIPassword = "xxx" profile.APISignature = "xxx" profile.Environment = "sandbox" caller.APIProfile = profile Dim encoder As New NVPCodec() encoder("VERSION") = "51.0" encoder("METHOD") = "GetTransactionDetails" encoder("TRANSACTIONID") = transactionID Dim pStrrequestforNvp As String = encoder.Encode() Dim pStresponsenvp As String = caller.[Call](pStrrequestforNvp) Dim decoder As New NVPCodec() decoder.Decode(pStresponsenvp) Return decoder("ACK") End Function End Class End Namespace I am using this to access that class: Private Sub cmdGetTransDetail_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdGetTransDetail.Click Dim thereturn As String thereturn =GetTransactionDetailsCode("test51322") End Sub But it keeps telling me: Error 2 Name 'GetTransactionDetailsCode' is not declared. I'm new at calling classes in VB.net so any help would be great! :o) David

    Read the article

  • How to post a file via HTTP post in vb.net

    - by Worz
    Hi all! Having a problem with sending a file via HTTP post in vb.net. I am trying to mimic the following HTML so the vb.net does the same thing. <form enctype="multipart/form-data" method="post" action="/cgi-bin/upload.cgi"> File to Upload: <input type="file" name="filename"/> <input type="submit" value="Upload" name="Submit"/> </form> Hope someone can help!

    Read the article

  • dllimport C++ DLL In VB.net

    - by JFLow
    Hi Experts out there, I'm stuck at dll imports with the c++ dll and i really need help to get over this. Here is the function in the c++ dll that i want to call from my VB.net code. bool LoadNewTestPlan(const char* szPlanFileName=" "); I've tried many ways in my VB.net but always getting the error : "Attempted to read or write protected memory. This is often an indication that other memory is corrupt." I have tried passing in byte(), Marshalling with LPStr, SafeArray and nothing works. Here is the example of my code code within the module <DllImport("HPVKIfc.dll", EntryPoint:="?LoadNewTestPlan@HPVKIfc@@QAE_NPBD@Z", CharSet:=CharSet.Ansi)> _ Public Function LoadNewTestPlan(<MarshalAs(UnmanagedType.LPStr)> ByVal pln As String) As Boolean End Function Do you see anything wrong? Thanks in advance.

    Read the article

  • Using AesCryptoServiceProvider in VB.NET

    - by Collegeman
    My problem is actually a bit more complicated than just how to use AES in VB.NET, since what I'm really trying to do is use AES in VB.NET from within a Java application across JACOB. But for now, what I need to focus on is the AES implementation itself. Here's my encryption code Public Function EncryptAES(ByVal toEncrypt As String, ByVal key As String) As Byte() Dim keyArray = Convert.FromBase64String(key) Dim toEncryptArray = Encoding.Unicode.GetBytes(toEncrypt) Dim aes = New AesCryptoServiceProvider aes.Key = keyArray aes.Mode = CipherMode.ECB aes.Padding = PaddingMode.ISO10126 Dim encryptor = aes.CreateEncryptor() Dim encrypted = encryptor.TransformFinalBlock(toEncryptArray, 0, toEncryptArray.Length) aes.Clear() Return encrypted End Function Once back in the Java code, I turn the byte array into a hexadecimal String. Now, to reverse the process, here's my decryption code Public Function DecryptAES(ByVal toDecrypt As String, ByVal key As String) As Byte() Dim keyArray = Convert.FromBase64String(key) Dim toDecryptArray = Convert.FromBase64String(toDecrypt) Dim aes = New AesCryptoServiceProvider aes.Key = keyArray aes.Mode = CipherMode.ECB aes.Padding = PaddingMode.ISO10126 Dim decryptor = aes.CreateDecryptor() Dim decrypted = decryptor.TransformFinalBlock(toDecryptArray, 0, toDecryptArray.Length) aes.Clear() Return decrypted End Function When I run the decryption code, I get the following error message Padding is invalid and cannot be removed.

    Read the article

  • Need Simple way to access XML in VB.Net - Pain with Linq-to-Xml

    - by aiart
    Dim myXDoc As XDocument = _ I want to access this in a simple way in VB.Net - Like: Dim Integer SizeXStr = CInt(MyZDoc.Cameras(1).Camera_Desc.@SizeX) ' where (1) is an index Why isn't this implemented in VB.Net? Better yet, type the values with a Schema and eliminate the conversion. Is this so hard? How do I access, in a simple way, data in XML - this would be VERY VERY useful! I have been using Query to try to get the values - when I use MsgBox() to display results, they display, but my main Windows Form is Trashed - changed colors, etc. The system has Bugs. Instead, I have to create an elaborate structure of arrays of objects and read the XML line-by-line and do the same for saving - this is the dark ages. Art

    Read the article

  • PHP + SQL Server or VB.NET + MySQL

    - by Muhammad Mussnoon
    Can someone suggest that out of the two mentioned (odd?) combinations, which is less odd, or in other words, is less trouble to work with + maintain. If it helps, the system is going to have two front-ends - one web application and one desktop application. The desktop application is going to be coded using VB.NET, and the web application in PHP. There's really no reason why the desktop application can't be replaced by a web application as well - except that one of the programmers seem to really want to code it in VB.... However, none of us have experience working with either of these pairs (you could easily call us n00bs), so we are a bit apprehensive to start. P.S. hosting service will be gotten from some provider and not be on the client's own server.

    Read the article

  • Convert C# event handling to VB.NET

    - by Quandary
    Question: The following C# code: public event RemoteAPI.NotifyCallback Notify { add { s_notify = value; } remove { Console.WriteLine("TODO : Notify remove."); } } How do I convert this to VB.NET ? It implements an interface: Public Interface ICallsToServer ''' <summary> ''' Function to call the server from the client ''' </summary> ''' <param name="n">Some number</param> ''' <returns>Some interesting text</returns> Function SomeSimpleFunction(ByVal n As Integer) As String ''' <summary> ''' Add or remove callback destinations on the client ''' </summary> Event Notify As NotifyCallback End Interface The VB.NET automatically generated code was: Public Event Notify(ByVal s As String) Implements RemoteAPI.ICallsToServer.Notify

    Read the article

  • DataList Control in vb.net windows application forms

    - by KoolKabin
    Hi guys, I am upgrading my application from vb6 to vb.net. I used to populate my data in datalist control in vb6 forms. I am not finding it in vb.net windows form application. Which one control is the equivalent to it? How can i list my data in that control? just like: I had a table with data like id, name I want the name should be the displayed column and id the bound column? how can i do that

    Read the article

  • set label value in vb.net

    - by julio
    Hi-- I'm usually a PHP guy but got stuck doing a project in vb.net. I have a query (sqldatasource) that returns a single value (the last update date). I want to use a label to say something like "Last updated: " < Label = (returned value) In PHP this would be simple. In vb.net, all I can find are endless badly written code behinds showing how you'd execute the query onLoad then bind it to the label. Is this really the only way to do this? It seems like a ridiculously simple problem to have such a long solution. I have used a datagrid control to just bind the query result directly, but it prints the column name as well as the date, so it's not ideal. Any ideas?

    Read the article

  • In VB.NET how do you specify Inherits/implements on a generic class with multi-constraints

    - by Romel Evans
    When I write the following statement in VB.Net (C# is my normal language), I get an "end of statement expected" referring to the "Implements" statement. <Serializable()> _ <XmlSchemaProvider("EtgSchema")> _ Public Class SerializeableEntity(Of T As {Class, ISerializable, New}) _ Implements IXmlSerializable, ISerializable ... End Class The C# version that I'm trying to emulate is: [Serializable] [XmlSchemaProvider("MySchema")] public class SerializableEntity<T> : IXmlSerializable, ISerializable where T : class, new() { .... } Sometimes I feel like I have 5 thumbs with VB.NET :)

    Read the article

  • Yield In VB.NET

    - by MagicKat
    C# has the keyword called yield. VB.NET lacks this keyword. I am curious how some of the VB programmers have gotten around the lack of this keyword. Do you implement your own iterator class? Or do you try and code to avoid the need of an iterator? The yield keyword does force the compiler to do some coding behind the scenes. http://blogs.msdn.com/oldnewthing/archive/2008/08/12/8849519.aspx is a good example of that.

    Read the article

< Previous Page | 3 4 5 6 7 8 9 10 11 12 13 14  | Next Page >