C# - Use Flush Parameter With Encoder.GetBytes Method?

Oct 4, 2010

This link explains the Encoder.GetBytes Method and there is a bool parameter called flush explained too . The explanation of flush is : true if this encoder can flush its state at the end of the conversion; otherwise, false. To ensure correct termination of a sequence of blocks of encoded bytes, the last call to GetBytes can specify a value of true for flush.but I didn't understand what flush does?

View 3 Replies


ADVERTISEMENT

When Should Call The Flush() Method

Jul 22, 2009

When should I call the Flush() method (TextWriter.Flush() / StreamWriter.Flush() / BinaryWriter.Flush() / etc) ? Should I call it everytime I finish writing a stream?

View 3 Replies

C# - What 'length' Parameter Should I Pass To SqlDataReader.GetBytes()?

Feb 7, 2011

I have a SqlDataReader and need to read a varbinary(max) column from it using the SqlDataReader.GetBytes() method. This method populates a byte array and therefore needs to know what length of data to read.This is where I get confused.. Clearly I want to read all the data that has been returned from the database in this row/column so what 'length' parameter should I pass?As far as I can see, the SqlDataReader doesn't provide any methods to discover what length of data is available, therefore this method seems fairly awkward to me.I'm tempted to just pass int.MaxValue here and forget about the issue but something about this doesn't sit right with me.

I am aware that I can instead call

byte[] value = (byte[])dataReader["columnName"];

.. and this seems to completely take care of the length issue internally. However I am working with a set of complicated code generation templates that have been built around the SqlDataReader.GetXXXX() methods. So I am tied into using GetBytes and need to understand its proper usage.

View 7 Replies

C# - What 'length' Parameter Should Pass To SqlDataReader.GetBytes()

Jun 21, 2012

I have a SqlDataReader and need to read a varbinary(max) column from it using the SqlDataReader.GetBytes() method. This method populates a byte array and therefore needs to know what length of data to read.This is where I get confused.. Clearly I want to read all the data that has been returned from the database in this row/column so what 'length' parameter should I pass?As far as I can see, the SqlDataReader doesn't provide any methods to discover what length of data is available, therefore this method seems fairly awkward to me.I'm tempted to just pass int.MaxValue here and forget about the issue but something about this doesn't sit right with me.

View 2 Replies

C# - Binarywriter.flush() Also Flush The Underlying Filestream Object?

Jun 1, 2010

I have got a code snippet as follows:

Dim fstream = new filestream(some file here)
dim bwriter = new binarywriter(fstream)
while not end of file
read from source file
bwriter.write()
bwriter.flush()
end while

The question I have is the following. When I call bwriter.flush() does it also flush the fstream object? Or should I have to explicitly call fstream.flush() such as given in the following example:

[Code]...

A few people suggested that I need to call fstream.flush() explicitly to make sure that the data is written to the disk (or the device). However, my testing shows that the data is written to the disk as soon as I call flush() method on the bwriter object.

View 1 Replies

"Value Cannot Be Null Parameter Name: Encoder" When Trying To Save An Image To Memorystream?

Jun 28, 2011

i have an image in an bytearray. I convert thiy bytearray to an image an do a resize on it which works fine. But after that i want to convert it back to a bytearray and then i get a "Value Cannot be null Parameter name: encoder" Exception when trying to do a IMG.SAVE(MEMORYSTREAM, IMAGE.RAWFORMAT)

[Code]....

View 1 Replies

AddressOf With Parameter - Method Which Requires A Parameter To Be Passed In

Mar 1, 2009

I have a method which requires a parameter to be passed in. I would like to use the Addhandler to call the method through a dynamically created button control's click event.

When I include () in the AddressOf, VS complains: 'AddressOf' operand must be the name of a method (without parentheses).

When I exclude the brackets, VS complains: Method '...' does not have a signature compatible with delegate...

My code:

CODE:

View 5 Replies

Pass A Method Like A Parameter Of Another Method

Feb 4, 2011

Is there a way to choose between different methods and pass one into another method ?

Sub conditionnal_binding(ByVal list_box_reference As ListBox, ByVal list_box_final As ListBox, _
ByVal dico_source As Dictionary(Of String, List(Of String)), _
ByVal my_methode As ??? )
' DO SOMETHING
End Sub

I wrote ??? because I don't know how to call another method inside a method.
I would like to choose between different "sub-methods". Here is how I would like to use my method :

conditionnal_binding(ListBox1, ListBox3, HTML.dico_basic_attribut, best_method)
conditionnal_binding(ListBox1, ListBox3, HTML.dico_basic_attribut, some_method)
conditionnal_binding(ListBox1, ListBox3, HTML.dico_basic_attribut, another_method)

View 5 Replies

Populate A List(Of Object) In A Class Method, Where The List Was Passed To The Method As A Parameter

Aug 13, 2011

I'm trying to code a class of RandomNumber. One of the class methods needs to populate a "List (Of RandomNumber)" ... which was passed as a parameter to the method ... with 10 random numbers between 1 and 50. DEAD SIMPLE :)

View 6 Replies

Flush With Top Right (Right-Align)?

May 7, 2010

I'm working in Visual Basic Express 2008, and have created a little application to run a marquee to display information for our hospital, that will auto-update.

I am trying to position the form to sit flush with the top-right portion of the screen. I set the position manually, to 800,0 which does move it to about the area i'm looking for, but depending on resolution (which varies throughout the facility) it will not sit flush with the right side of the screen.

Is there anyway to set form parameters to right-align?

View 4 Replies

Getting E.graphics As A Parameter To A Method?

Mar 30, 2010

I have a a method drawPaper(g, rect,.....).This drawPaper method is called on from another method (PrintPaper method) with the parameters passed on as (e.graphics, rect, .....) i.e drawpaper (e.graphics, rect, .....) why is the method called with the e.graphics argument not with g as per the method.

View 6 Replies

Access A Method's Parameter From An Associated Attribute?

Mar 19, 2009

Given the following classes, how can i intercept Class1.SampleMethod's Value from SampleAttribute?[code]...

View 2 Replies

Invoke A Method With (of T) Parameter Using Reflection

May 5, 2011

I'm trying to make this code with reflection since I want it to manage Technician and other types too.

[Code]....

View 1 Replies

Method Parameter Name Same As Class Property?

Apr 21, 2010

Is it accepted to have a method parameter named the same as a property? At least it gives no error, even if in the same letter-case.. How does the compiler distinguish? does it always prioritize the local parameter?

[Code]...

View 4 Replies

Method/sub That Takes An Object As A Parameter?

Dec 23, 2010

I have a method/sub that takes an object as a parameter, then it scans through a panels controls and trys to find if it is in the window.

Public Sub removetype (ByVal findobject As Object)
Dim types As System.Type = findobject.GetType
For Each ThisCtrl In Flow.Controls 'flow is a panel

[Code]......

View 3 Replies

.net - Passing A Method (that Returns A Value) As A Parameter A Bad Thing?

May 21, 2012

So for instance I have this method: LoadFunkyInfo(byval funkyData as string) And I pass it something like this:

LoadFunkyInfo(giantTable.Rows.Item(0).Item("blahName")). Should I do this instead?

dim foo as string = giantTable.Rows.Item(0).Item("blahName")
LoadFunkyInfo(foo)

I read somewhere long ago, that it's better to assign the method to a variable and pass that variable to a method, as opposed to passing the method as a parameter. Is that still true? Or true at all?

View 5 Replies

Optional Method Parameter And String.Empty?

Apr 19, 2012

I have traditionally coded empty strings like this "", but for a couple of years now, I have been using String.Empty.I also normally never use optional parameters, but I'm refactoring a solution that's tied into my ERP, and I don't want to break anything. One of the changes was to add a parameter to proc, which pushes a new parameter into the method from which it is called. I coded it like this:

Optional BackReferenceID As String = String.Empty

But I got a syntax error "Constant expression is required." I guess String.Empty is non-deterministic??? Anyway, it seems like a bug. The workaround is of course to use double quotes.

View 1 Replies

Pass An Object As A Parameter To A Fortran Method?

Aug 25, 2010

I'm currently working on being able to import a DLL written in Fortran into Visual Basic. I've got all the basics down, so now I'm trying to take it a step further. The title basically says it all, but I'll explain what it is I'm trying to do anyways.

For kicks and giggles, let's just assume I want to pass an object that has three double values in it, possibly representing a point in space in three dimensions. In my Fortran method, I want to take that object, print out the x value, then change the x value to 7.5. Here's my Fortran code that does just that.[code]...

View 2 Replies

Passing Parameter (Value Or Referenced Type) Into Method?

Nov 11, 2009

What happened when parameter passing. Here is a test project I write.
Public Class Form1
'1.test string
Private Sub btnString_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnString.Click
Dim str1 As String = "x"
[Code] .....

From the project you can see, when pass integer type parameter (value type) into a method , if use ByVal keyword, the value won't change. If use ByRef keyword, the value will change (I can understand it, to my understanding, when using ByVal, It pass the value of the argument to the method; when using BvRef, it pass the address of the argument to the method, so the value can be rewrite)

Well, for the following two scenarios , I can't understand why.
String type is reference type, but it acts like integer type.
Val type is also reference type, but no matter what you use(ByVal or ByRef), the result will be the same.
So my question is what actually passed into method? What's the underlying mechanism about pass parameter? What's the effect of ByRef and ByVal to value type and reference type?

View 1 Replies

Pass Null Parameter Fill Method Of Tableadapter?

Jan 17, 2012

I have already defined in my SELECT statement in TableAdapter to tell it what to do if the parameters are Null:

SELECT a.ID, a.NameID, b.BNameID
FROM a INNER JOIN b
ON a.ID = b.ID
WHERE ((@NameID IS NULL) OR (a.NameID = @NameID))
AND ((@BNameID IS NULL) OR (b.BNameID = @BNameID))

View 4 Replies

Passing Date Parameter To DataTable.Select() Method

Apr 9, 2009

Jst recently i came across the select() method of data table and felli n love with it instantaneously.

Basically I want query the data table on a date field, unfortunately the format of the date string returned from y database in to data-table and the date string i'm passing as inputs are different.

How can i make sure that the data is compared irrespective of the formats ? Can I use something like SqlParameters whoes data type is date for comparison ??

this is what i'm tying :

dim dat as date = "#1/3/2009#"
dt.select("StzDate ='" & dat "'")
entry in datateable dt : StzDate : 3/1/2009 12:00:000
Am I do'in something wrong ??

Also, can anyone redirect me to some site where I can learn a bit more about passing parameters to the select statement,etc...

View 2 Replies

C# - Pass An Integer As A String Parameter To A Method Without Calling .ToString()?

Mar 12, 2010

In VB.NET, it is entirely possible to pass an integer as a string parameter to a method without calling .ToString() - it's even possible to call .ToString without the ()'s. The code will run without a problem, VB will interpret the integer as a string without having been told to. In C#, these would cause compilation errors - you are required to call .ToString() and to call it correctly in that situation before it will compile. Is there a way to make the VB compilation process check for the same things as the C# compilation process? Would it be best practice in a mixed team to force this check?

View 3 Replies

Why Encoding.Default.GetBytes() Returns Different Results In C#

May 29, 2009

We recently came across some sample code from a vendor for hashing a secret key for a web service call, their sample was in VB.NET which we converted to C#. This caused the hashing to produce different input. It turns out the way they were generating the key for the encryption was by converting a char array to a string and back to a byte array. This led me to the discovery that VB.NET and C#'s default encoder work differently with some characters.

C#:
Console.Write(Encoding.Default.GetBytes(new char[] { (char)149 })[0]);

VB:
Dim b As Char() = {Chr(149)}
Console.WriteLine(Encoding.Default.GetBytes(b)(0))

The C# output is 63, while VB is the correct byte value of 149.if you use any other value, like 145, etc, the output matches.Walking through the debugging, both VB and C# default encoder is SBCSCodePageEncoding.I have corrected the sample code by directly initializing a byte array, which it should have been in the first place, but I still want to know why the encoder, which should not be language specific, appears to be just that.

View 5 Replies

Generic BitConverter.GetBytes For Primitive Data Types?

Jan 19, 2012

addressing the need for getting the bytes of an object. But I am wondering if there is an approach to calling BitConverter.GetBytes on a generic type where I know the type is a primitive (Int32, UInt16, etc).

Public Sub Foobar(Of T as Structure)()
Dim x as T 'Assume T is declared as Int32
Dim y() as Byte
y = System.BitConverter.GetBytes(x)
End Sub

The above will throw your usual error:

Overload resolution failed because no accessible 'GetBytes' can be called with these arguments:
'Public Shared Function GetBytes(value As Double) As Byte()': Value of type 'T' cannot be converted to 'Double'.
'Public Shared Function GetBytes(value As Single) As Byte()': Value of type 'T' cannot be converted to 'Single'.

[code]....

One solution I think would work is a large Select Case calling GetType(), but that is horrendously slow (because of boxing) and looks ugly. I would think that since I call my higher level class with a primitive data type for T, that the compiler would be smart enough to figure it out, but I assume I am not providing enough information for it to derive what T's underlying value is at compile time for the invoked instances.

View 6 Replies

Using Windows Media Encoder SDK To Convert WAV To WMA?

Sep 15, 2009

I have downloaded and installed the Windows Media Encoder and the SDK. I am trying to convert WAV files to WMA files (& vice versa) using VB2005 Pro. I have found plenty of examples on google for working with video but no examples for audio.

View 1 Replies

2005 - Discard The Contents Of A System.Net.Sockets.Socket Send Buffer Using TheSocket.IOControl(IOControlCode.Flush

Jun 10, 2012

I'm attempting to discard the contents of a System.Net.Sockets.Socket send buffer using theSocket.IOControl(IOControlCode.Flush, .... Does anybody know whether VB.NET supports this command? I've tried supplying 'Nothing' and 'Nothing' for both required parameters, also empty and populated byte arrays in combination with 'Nothing' for both required parameters, but I consistently get an 'Invalid argument' exception. I've tried a web search for an answer, but the only mention I've found was a question asked about 8 years ago, with still no answer.

View 1 Replies

VS 2010 Get String/Binary Code/Encoder?

May 22, 2010

I need to know how to crypt that:

Const FileSplit = "@vorfin@"

Cause its appearing on HEX Source.

View 6 Replies

.net - Silverlight UTF8 Encoder Produces Wacky Output?

Oct 14, 2010

I've been trying to trace down a bug for hours now and it has come down to this:

Dim length as Integer = 300
Dim buffer() As Byte = binaryReader.ReadBytes(length)
Dim text As String = System.Text.Encoding.UTF8.GetString(buffer, 0, buffer.Length)

The problem is the buffer contains 300 bytes but the length of the string 'text' is now 285. When I convert it back to bytes, the length is 521 bytes...The same code is a normal WinForms app works perfectly. The data being read by the binary reader is a UTF8 encoded string. Any ideas why Silverlight is playing funny buggers?

View 1 Replies

Screen Recorder Using Windows Media Encoder SDK Not Working

May 19, 2009

I was looking up how to make a screen recorder when I ran into a source code that uses Windows Media Encoder SDK. I tried it out and it crashes saying that Data Execution Protection stopped the program. So, I debugged the program and found that when it creates a new instance that this is the cause of the crash. [code]

View 1 Replies

Using The Classes From System.Drawing.Imaging, Esp. Encoder, EncoderParameters

May 5, 2010

Exists a good tutorial or example that shows how to use these classes from namespace System.Drawing.Imaging.

My idea is, to produce Bitmaps and to compress them. I don't know if for my case IO Streaming is important because I don't want to save the bitmap on my hard disk.

View 3 Replies







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