Thank you all for your input! I certainly was happy that this issue had a lot of interest. "i would hope that anybody who is working in IT knows the relationships between bits bytes k, m, g, t.....and on and on." -- knowing the relationship between bytes, KB, MB, etc.. was irrelevant as I was asking if there was a class/method that automatically did the conversions in VB.Net. And yes, I know the relationship between them :P "I think he meant: no need for me to test it, just publish and wait a while." -- Yea I'm sure all programmers are perfect testers of THEIR own code. I did some testing, but it obviously wasn't good enough. I suppose that's what learning is.. no? "What if file is exactly 1024 or 1048576 bytes?" -- Good point! I was swamped with work that I overlooked that fault. Thank you. "But there's even worse when you look at it more closely e.g. a file of 1023 bytes returns 1,023.00KB." -- Another good point. I need to address all eventualities more closely! "I decide to benefit and wrote something that does work." -- Thank you. I will work through that code. Thanks again all! This made my day.
Dayekh
Posts
-
Filesize Conversion -
Filesize ConversionNot at all, that was intentional. However I should have been clearer. The reason that code block refers to formatting in KiloBytes is because I would like any file that is less than 1024 to be displayed as KB as well. For example a file that is 643 Bytes big will appear as 0.64KB Cheers.
-
Filesize ConversionThank you all for your input. I have finally written a function to do exactly what I need to be done. Please look at the code below and benefit from it if you wish:
Public Function BytesFormatting(ByVal Bytes As Integer) As String Dim FormattedFileSize As Double If Bytes < 1024 Then ''code to format fsize as KB Dim dblFormatted As Double dblFormatted = Bytes FormattedFileSize = Format(dblFormatted, "###,###.00") + "KB" ElseIf (Bytes > 1024 And Bytes < 1048576) Then ''code to format fsize as KB Dim dblFormatted As Double dblFormatted = (Bytes + 1023) / 1024 FormattedFileSize = Format(dblFormatted, "###,###.00") + "KB" ElseIf Bytes > 1048576 Then ''code to format fsize as MB Dim dblFormatted As Double dblFormatted = (Bytes / 1024) / 1024 FormattedFileSize = Format(dblFormatted, "###,###,###.00") + "MB" End If Return FormattedFileSize.ToString End Function
-
Filesize ConversionI found to format it, but I'm still getting errors.. I will post update this when I work it out.
-
Filesize ConversionI would like to know if there is function in built that converts filesizes automatically. For instance if there is a file that is 1234 bytes, it will be represented as 1.23 KB, or if we have a file that is 1234567, it will be represented as 1.23 MB. Or anything along these lines.
-
Filesize ConversionHi all, I'm finding it hard to work with file conversion in VB.Net. I already have the filesize in Bytes, but I need to display it as KB in a repeater. The examples on google are too complex for what I need. Any help is appreciated. Thanks.
-
Looping through a repeaterHi all, I'm trying to bind a child repeater within a parent repeater by counting through all the rows of the parent repeater and for every row I would like to bind the child repeater. I need help with the way it works.. this is what I have so far:
Sub BindParent()
'Bind Parent
End SubPublic Sub rpParent_Databound(ByVal sender As Object, ByVal e As RepeaterItemEventArgs)
For Each Item As RepeaterItemCollection In rpParent.Items
'Bind Child
Next
End SubCurrently each Child row has a Parent row. I would like there to be a Parent row with many Child rows, and then the next Parent row would appear. Basically it is not counting correctly. I hope all this makes sense :confused:
-
Validation IssueThanks for that :)
-
Validation IssueOh dear! I solved it. just for others to know my silly mistake... I need to make the "ValidationGroup" for each button of the each group the same as what was applied in the controls of that group. e.g.
-
Validation IssueHi guys, I have 3 submit buttons on a single page. Each submit button is linked to its controls via a "ValidationGroup". One of the groups even has a Custom Validator. The problem I am having is that the validation is not even firing. I have no idea why. I hope the answer is not silly :( Here is the HTML for ONE of the groups:
<div id="dvRegistrationValidation" runat="server">
<asp:RequiredFieldValidator ID="rfvRegistrationCode" ControlToValidate="txtRegistrationCode"
Display="None" ValidationGroup="RegistrationProcess" ErrorMessage="Registration Code"
runat="server"></asp:RequiredFieldValidator>
<asp:CustomValidator ID="cstTarget" runat="server" ErrorMessage="Either Head Office or Farm Site/Unit"
ValidationGroup="RegistrationProcess" OnServerValidate="cstTarget_ServerValidate"
Display="None"></asp:CustomValidator>
<asp:ValidationSummary ID="vsRegistration" runat="server" DisplayMode="BulletList"
ShowSummary="true" HeaderText="The following fields are mandatory:" ValidationGroup="RegistrationProcess" />
</div>And here is the OnServerValidate Sub Routine:
Sub cstTarget\_ServerValidate(ByVal source As Object, ByVal e As ServerValidateEventArgs) Handles cstTarget.ServerValidate If Me.chkTarget1.Checked = True And Me.chkTarget2.Checked = True Then e.IsValid = False ElseIf Me.chkTarget1.Checked = False And Me.chkTarget2.Checked = False Then e.IsValid = False ElseIf Me.chkTarget1.Checked = True And Me.chkTarget2.Checked = False Then e.IsValid = True ElseIf Me.chkTarget1.Checked = False And Me.chkTarget2.Checked = True Then e.IsValid = True End If End Sub
I appreciate any help given. Thanks!
-
Repeater No. of repeats!Hi guys, I am an intermediate when it comes to the repeater control. I would like to restrict the repeater to get the first 5 columns of the table. Is there a way to accomplish this without paging? Paging is more complex for a repeater and I would like to avoid it. I do no even need paging, just the first 5 results. Thanks for any help or hints! :)
-
Returning 2 output parameters in Stored ProcedureI suppose that makes sense. Normally I check if the return value is > 0, I suppose if a Stored Procedure executes successfully, then my parameter should be > 0 and I can just check that. Thanks for your reply.
-
Returning 2 output parameters in Stored ProcedureHi guys, I'm trying to get 2 values from a stored procedure: one telling me the execution was successful and another for telling me what the newly inserted ROW ID is. I currently have the following:
USE [xyz] GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO ALTER PROCEDURE [dbo].[spName] ( @vchName VarChar (50), @intSuccess Numeric(9) OUT ) AS SET XACT_ABORT ON BEGIN TRANSACTION INSERT INTO Table ( vchName ) VALUES ( @vchName ) IF @@ERROR <> 0 BEGIN SELECT @intSuccess = 0 ROLLBACK END ELSE SELECT @intSuccess = 1 /* SET NOCOUNT ON */ COMMIT TRANSACTION SET XACT_ABORT OFF RETURN @intSuccess
Currently it returns the value "@intSuccess" ONLY. I want to add the line "SELECT @@IDENTITY AS inLatestID" right under the insert statement so I can get the latest ID value of the record that was just newly inserted. I think I will need to return another value alongside @intSuccess, but I'm not sure how that works in the Stored Procedure -
Retrieving data in partsThanks for the reply. I will research Custom Paging. I'm sure the answer lies there. Cheers!
-
Retrieving data in partsThanks for the input.. check out my reply to the previous post. I still have one issue :(
-
Retrieving data in partsHi Luc, Thanks for the reply. Let me just make things clear. 1 - I will store the small details in the Article table. 2 - I will store the parts of the articles as separate records in a "Parts" table. 3 - Each part will have an article ID. 4 - I will call details FROM article table AND parts table WHERE ID is the one clicked on by the user One last problem: Due to the user being able to store ANY number of parts PER article, how do I connect each part to a repeater? I would like the repeater to do "Paging" on each part. Is that possible?
-
Retrieving data in partsHi all, I'm trying to allow the user to store an article in a table where the article body can take ANY number of parts each displayed as a separate page on a webpage. I thought I would store the entire article in the Article table but separated by a delimiter like, the only problem is, after I store the record, how would I go ahead a retrieve the data IN PARTS so that it can be displayed in a repeater?
-
Detect an external email addressGood Call.. I will do that.. I shall use an encryption algorithm. Thanks!
-
Detect an external email addressThanks for the answer! I see what you mean.. query the email that they input and send it to his email.. when it arrives back to the application, it will be there ready for me to query! Sometimes the solution is soo simple! Thanks again :D
-
Detect an external email addressHi all, I am trying to code a procedure in VB.Net where a user clicks on a link and the page detects the email of the person. This way I will be able to validate that it is a new user who has accessed the activation aspx page. Currently, I have the follwing:
IF Request.QueryString("uid") > 0 THEN 'activate user ELSE 'display error message END IF
I can also query the DB to see if the userID is > 0 AND if the activation status is false, but it is still not specific enough. If I can include his EMAIL ADDRESS in the query, I will have solved the issue. Thanks for your help!