首页 \ 问答 \ 1迭代后的循环停止(For-Loop Stopping after 1 Iteration)

1迭代后的循环停止(For-Loop Stopping after 1 Iteration)

对于我的这部分工作,我需要做以下事情:

创建一个函数,该函数返回字符串类型键和整数类型值的排序列表。 在函数内部,声明一个新的排序列表,其结构与函数的返回类型相同。 然后,使用嵌套for循环填充排序列表,浏览产品列表和年份列表,以便将产品和年份连接在一起以创建密钥,并从请求表数组中检索相应的需求值作为值将此键输入到排序列表中。

我编写了以下代码来执行此操作,但是在1次迭代后它会在System.dll中抛出“System.ArgumentException”。 测试MessageBox将仅显示“ModelX 2013 205”,然后将抛出错误。

    Public Function GetProductDemand() As SortedList(Of String, Integer)
    Dim prodDemand As New SortedList(Of String, Integer)

    Dim count As Integer = 0
    For Each product In products
        For Each yr In years
            Dim key As String
            key = product & " " & yr
            For i As Integer = 0 To 4
                prodDemand.Add(key, demand(count, i)) 'stops here after 1 iteration
                MessageBox.Show(key & " " & prodDemand(key)) 'test to display results
            Next
        Next
        count += 1
    Next
    Return prodDemand
End Function

出现这种情况的原因是什么? 以下是相关代码的其余部分:

    Dim products As List(Of String)
Dim years As List(Of String)
Dim demandList As SortedList(Of String, Integer)
Dim demand As Integer(,)

Private Sub frmDemand_Load(sender As Object, e As EventArgs) Handles MyBase.Load
    products = GetProducts()
    years = GetYears()
    demand = GetDemand()
    demandList = GetProductDemand()
End Sub

Private Function GetDemand() As Integer(,)
    Return {
            {205, 220, 245, 230},
            {160, 174, 152, 144},
            {480, 424, 396, 456}
           }
End Function

Public Function GetProducts() As List(Of String)
    Dim prods As New List(Of String)
    prods.Add("ModelX")
    prods.Add("ModelY")
    prods.Add("ModelZ")
    Return prods
End Function

Public Function GetYears() As List(Of String)
    Dim yr As New List(Of String)
    yr.Add("2013")
    yr.Add("2014")
    yr.Add("2015")
    yr.Add("2016")
    Return yr
End Function

For this part of my assignment I need to do the following:

Create a function that returns a sorted list of string type keys and integer type values. Inside the function, declare a new sorted list that has the same structure as the function’s return type. Then, using a nested for loop for populating the sorted list, go through the product list and year list such that the product and year is concatenated together to create a key, and the corresponding demand value from the demand table array is retrieved as the value for this key to be entered to the sorted list.

I've written the following code to do that, however it throws "'System.ArgumentException' in System.dll" after 1 iteration. The test MessageBox will only display "ModelX 2013 205" and then the error will be thrown.

    Public Function GetProductDemand() As SortedList(Of String, Integer)
    Dim prodDemand As New SortedList(Of String, Integer)

    Dim count As Integer = 0
    For Each product In products
        For Each yr In years
            Dim key As String
            key = product & " " & yr
            For i As Integer = 0 To 4
                prodDemand.Add(key, demand(count, i)) 'stops here after 1 iteration
                MessageBox.Show(key & " " & prodDemand(key)) 'test to display results
            Next
        Next
        count += 1
    Next
    Return prodDemand
End Function

Any reason why this is happening? Here's the rest of the relevant code:

    Dim products As List(Of String)
Dim years As List(Of String)
Dim demandList As SortedList(Of String, Integer)
Dim demand As Integer(,)

Private Sub frmDemand_Load(sender As Object, e As EventArgs) Handles MyBase.Load
    products = GetProducts()
    years = GetYears()
    demand = GetDemand()
    demandList = GetProductDemand()
End Sub

Private Function GetDemand() As Integer(,)
    Return {
            {205, 220, 245, 230},
            {160, 174, 152, 144},
            {480, 424, 396, 456}
           }
End Function

Public Function GetProducts() As List(Of String)
    Dim prods As New List(Of String)
    prods.Add("ModelX")
    prods.Add("ModelY")
    prods.Add("ModelZ")
    Return prods
End Function

Public Function GetYears() As List(Of String)
    Dim yr As New List(Of String)
    yr.Add("2013")
    yr.Add("2014")
    yr.Add("2015")
    yr.Add("2016")
    Return yr
End Function

原文:https://stackoverflow.com/questions/42426120
更新时间:2022-02-26 22:02

最满意答案

根据文档,有一个函数MagickGetImageBlob返回unsigned char * ,这看起来就像你在寻找。 它的确切文件是

MagickGetImageBlob()实现直接到内存的图像格式。 它将图像作为blob(内存中的格式化“文件”)及其长度返回,从图像序列中的当前位置开始。 使用MagickSetImageFormat()设置要写入blob的格式(GIF,JPEG,PNG等)。

请注意,这确实需要您使用MagickSetImageFormat设置格式,但总体而言,这似乎是您所寻找的最接近的东西。


According to the documentation there is a function MagickGetImageBlob that returns unsigned char * which is seemingly what you are looking for. Its exact documentation is

MagickGetImageBlob() implements direct to memory image formats. It returns the image as a blob (a formatted "file" in memory) and its length, starting from the current position in the image sequence. Use MagickSetImageFormat() to set the format to write to the blob (GIF, JPEG, PNG, etc.).

Note that this does require you to set the format using MagickSetImageFormat, but on the whole this seems to be the closest thing to what you are looking for.

相关问答

更多
  • 我不认为有内置任何东西,但写起来很容易: (defun my-clone-and-open-file (filename) "Clone the current buffer writing it into FILENAME and open it" (interactive "FClone to file: ") (save-restriction (widen) (write-region (point-min) (point-max) filename nil nil ni ...
  • 您应该设置coding-system-for-write或者buffer-file-coding-system而不是使用set-language-environment 。 PS。 一般而言,您应该在代码中使用可能的最低级别函数(例如,帮助next-line明确建议使用代码中的forward-line代码)。 在你的情况下,你可能想要使用basic-save-buffer甚至是write-region 。 PPS。 你应该使用with-current-buffer而不是set-buffer 。 You sh ...
  • 期待来自bitbucket的最新pystacia代码我意识到pip的版本已经很老了(从2011年开始),最新代码的安装解决了我的问题 - 因为我可以负担得起运行未发布的代码。 我还在bitbucket上输入了一个问题,所以维护者发布了一个新的代码版本。 Looking to the latest pystacia code from bitbucket I realized that the version from pip is pretty old (from 2011) and a installat ...
  • 使用此代码在新文本文件中编写输出...这可能会对您有所帮助 包com.mkyong; import java.io.BufferedWriter; import java.io.File; import java.io.FileWriter; import java.io.IOException; public class WriteToFileExample { public static void main(String[] args) { try { String cont ...
  • 你可以在这里找到imagemagick的用法 这个链接对我来说非常有用。 I ended up using MagickCommandGenesis() to achieve the desired result.
  • 总之,你没有。 这个模块的重点恰恰在于猜测系统的默认临时目录,生成随机文件名并为您处理文件和目录删除。 从这个意义上说,对于保存和使用特定文件名称的地方颇有见地,您只能在系统的临时目录和前缀/后缀选项中指定文件夹名称。 关于将内容写入文件,您必须自己处理: var fs = require("fs"); var tmp = require("tmp"); tmp.file(function (err, path, fd, cleanup) { if (err) throw err; f ...
  • 正如评论中所讨论的那样,我认为确切的大小并不重要,假设它是: 是文件系统大小的一小部分(请参阅Joachim Pileborg对stat(".")等) 2的幂(因为像他们的电脑和内核) 不是太大(例如适合处理器内的某些缓存,例如L2缓存) 在内存中对齐(例如,使用posix_memalign指向页面大小)。 因此,16k字节到几兆字节之间的两个幂应该适合。 大部分时间都花在阅读磁盘上。 文件系统和磁盘基准测试在该范围内相当平坦。 4K字节似乎通常是页面大小和磁盘块大小。 当然,使用mke2fs (文件系统块 ...
  • 你想要的是随机访问IO(在文件中的特定点读取或写入)。 它没有在默认API中提供,但您可以使用其他软件包,如https://www.npmjs.org/package/random-access-file What you want is random access IO (read or write at a specific point in a file). It's not provided in the default API but you may use an additional packa ...
  • 根据文档,有一个函数MagickGetImageBlob返回unsigned char * ,这看起来就像你在寻找。 它的确切文件是 MagickGetImageBlob()实现直接到内存的图像格式。 它将图像作为blob(内存中的格式化“文件”)及其长度返回,从图像序列中的当前位置开始。 使用MagickSetImageFormat()设置要写入blob的格式(GIF,JPEG,PNG等)。 请注意,这确实需要您使用MagickSetImageFormat设置格式,但总体而言,这似乎是您所寻找的最接近的东 ...
  • 是的,这里有一些错误。 这将分配4或8字节的缓冲区,具体取决于计算机的字大小。 'sizeof'是一个编译时指令,它为您提供基础类型的大小。 char tmp [sizeof(_ log)]; 所以这样做(其中100只是一个足够大的数字来保存结果): char tmp [100]; 接下来使用char为'a'将无法保存EOF值。 使用int。 int a; 通过修复'a'的定义,你的循环现在不是无限的,但它最终会将常量EOF写入文件,这将是一些乱码。 像这样改变它: while((a = fgetc(fp1 ...

相关文章

更多

最新问答

更多
  • 您如何使用git diff文件,并将其应用于同一存储库的副本的本地分支?(How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?)
  • 将长浮点值剪切为2个小数点并复制到字符数组(Cut Long Float Value to 2 decimal points and copy to Character Array)
  • OctoberCMS侧边栏不呈现(OctoberCMS Sidebar not rendering)
  • 页面加载后对象是否有资格进行垃圾回收?(Are objects eligible for garbage collection after the page loads?)
  • codeigniter中的语言不能按预期工作(language in codeigniter doesn' t work as expected)
  • 在计算机拍照在哪里进入
  • 使用cin.get()从c ++中的输入流中丢弃不需要的字符(Using cin.get() to discard unwanted characters from the input stream in c++)
  • No for循环将在for循环中运行。(No for loop will run inside for loop. Testing for primes)
  • 单页应用程序:页面重新加载(Single Page Application: page reload)
  • 在循环中选择具有相似模式的列名称(Selecting Column Name With Similar Pattern in a Loop)
  • System.StackOverflow错误(System.StackOverflow error)
  • KnockoutJS未在嵌套模板上应用beforeRemove和afterAdd(KnockoutJS not applying beforeRemove and afterAdd on nested templates)
  • 散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)
  • android - 如何避免使用Samsung RFS文件系统延迟/冻结?(android - how to avoid lag/freezes with Samsung RFS filesystem?)
  • TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)
  • 企业安全培训的各项内容
  • 错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)
  • C#类名中允许哪些字符?(What characters are allowed in C# class name?)
  • NumPy:将int64值存储在np.array中并使用dtype float64并将其转换回整数是否安全?(NumPy: Is it safe to store an int64 value in an np.array with dtype float64 and later convert it back to integer?)
  • 注销后如何隐藏导航portlet?(How to hide navigation portlet after logout?)
  • 将多个行和可变行移动到列(moving multiple and variable rows to columns)
  • 提交表单时忽略基础href,而不使用Javascript(ignore base href when submitting form, without using Javascript)
  • 对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)
  • Angular $资源不会改变方法(Angular $resource doesn't change method)
  • 在Angular 5中不是一个函数(is not a function in Angular 5)
  • 如何配置Composite C1以将.m和桌面作为同一站点提供服务(How to configure Composite C1 to serve .m and desktop as the same site)
  • 不适用:悬停在悬停时:在元素之前[复制](Don't apply :hover when hovering on :before element [duplicate])
  • 常见的python rpc和cli接口(Common python rpc and cli interface)
  • Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)
  • 产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)